Skip to content

Commit

Permalink
Fix the include preprocessor creating nested diagrams (#314)
Browse files Browse the repository at this point in the history
* Fix the include preproc creating nested diagrams

Just remove the @start... and @EnD... from an included file.

Fixes #298

* Improve start and end diagram regex

Now also works with windows style line-endings.

* Fix end diagram regex to match the last occurence
  • Loading branch information
neumantm authored May 13, 2020
1 parent 5612ce9 commit 55c147c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/plantuml/diagram/include.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const INCLUDE_REG = /^\s*!(include(?:sub)?)\s+(.+?)(?:!(\w+))?$/i;
const STARTSUB_TEST_REG = /^\s*!startsub\s+(\w+)/i;
const ENDSUB_TEST_REG = /^\s*!endsub\b/i;

const START_DIAGRAM_REG = /(^|\r?\n)\s*@start.*\r?\n/i;
const END_DIAGRAM_REG = /\r?\n\s*@end.*(\r?\n|$)(?!.*\r?\n\s*@end.*(\r?\n|$))/i;

interface FileSubBlocks {
[key: string]: string[];
}
Expand Down Expand Up @@ -87,6 +90,10 @@ function getIncludeContent(file: string): string {
let result = resolveInclude(content, getSearchPaths(vscode.Uri.file(file)));
_route.pop();
// console.log('Leaving:', file);

result = result.replace(START_DIAGRAM_REG, "$1");
result = result.replace(END_DIAGRAM_REG, "$1");

return result;
}

Expand Down

0 comments on commit 55c147c

Please sign in to comment.