mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-18 23:09:49 +02:00
fix: Remove comment line completely
This commit is contained in:
@@ -14,11 +14,8 @@ graph TD
|
|||||||
%% This is a comment
|
%% This is a comment
|
||||||
`;
|
`;
|
||||||
expect(cleanupComments(text)).toMatchInlineSnapshot(`
|
expect(cleanupComments(text)).toMatchInlineSnapshot(`
|
||||||
"
|
"graph TD
|
||||||
|
|
||||||
graph TD
|
|
||||||
A-->B
|
A-->B
|
||||||
|
|
||||||
"
|
"
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
@@ -38,16 +35,13 @@ graph TD
|
|||||||
%% This is a comment
|
%% This is a comment
|
||||||
`;
|
`;
|
||||||
expect(cleanupComments(text)).toMatchInlineSnapshot(`
|
expect(cleanupComments(text)).toMatchInlineSnapshot(`
|
||||||
"
|
"%%{init: {'theme': 'forest'}}%%
|
||||||
|
|
||||||
%%{init: {'theme': 'forest'}}%%
|
|
||||||
%%{ init: {'theme': 'space before init'}}%%
|
%%{ init: {'theme': 'space before init'}}%%
|
||||||
%%{init: {'theme': 'space after ending'}}%%
|
%%{init: {'theme': 'space after ending'}}%%
|
||||||
graph TD
|
graph TD
|
||||||
A-->B
|
A-->B
|
||||||
|
|
||||||
B-->C
|
B-->C
|
||||||
|
|
||||||
"
|
"
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
@@ -61,11 +55,39 @@ graph TD
|
|||||||
C-->D
|
C-->D
|
||||||
`;
|
`;
|
||||||
expect(cleanupComments(text)).toMatchInlineSnapshot(`
|
expect(cleanupComments(text)).toMatchInlineSnapshot(`
|
||||||
|
"graph TD
|
||||||
|
A-->B
|
||||||
|
C-->D
|
||||||
"
|
"
|
||||||
graph TD
|
`);
|
||||||
A-->B
|
});
|
||||||
|
|
||||||
C-->D
|
it('should remove empty newlines from start', () => {
|
||||||
|
const text = `
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
%% This is a comment
|
||||||
|
graph TD
|
||||||
|
A-->B
|
||||||
|
`;
|
||||||
|
expect(cleanupComments(text)).toMatchInlineSnapshot(`
|
||||||
|
"graph TD
|
||||||
|
A-->B
|
||||||
|
"
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove comments at end of text with no newline', () => {
|
||||||
|
const text = `
|
||||||
|
graph TD
|
||||||
|
A-->B
|
||||||
|
%% This is a comment`;
|
||||||
|
|
||||||
|
expect(cleanupComments(text)).toMatchInlineSnapshot(`
|
||||||
|
"graph TD
|
||||||
|
A-->B
|
||||||
"
|
"
|
||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
@@ -4,5 +4,5 @@
|
|||||||
* @returns cleaned text
|
* @returns cleaned text
|
||||||
*/
|
*/
|
||||||
export const cleanupComments = (text: string): string => {
|
export const cleanupComments = (text: string): string => {
|
||||||
return text.trimStart().replace(/^\s*%%(?!{)[^\n]+/gm, '');
|
return text.trimStart().replace(/^\s*%%(?!{)[^\n]+\n?/gm, '');
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user