Skip to content

Commit

Permalink
Merge pull request #52 from johanhammar/mermaid-support-frontmatter
Browse files Browse the repository at this point in the history
fix: support mermaid diagrams with frontmatter directives
  • Loading branch information
johanneswuerbach authored Jun 28, 2024
2 parents 5f63012 + 7b0a8b4 commit 21d5b7f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/Mermaid/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,29 @@ A-->B`;

expect(isMermaidCode(mermaidCode)).toBe(true);
})

it("mermaid code exists with frontmatter", () => {
const mermaidCode = `---
title: class diagram with frontmatter
---
classDiagram
direction LR`;

const result = isMermaidCode(mermaidCode);

expect(result).toBe(true);
});

it("mermaid code exists with comment", () => {
const mermaidCode = `%% mermaid code with comment
graph LR
A-->B`;

const result = isMermaidCode(mermaidCode);

expect(result).toBe(true);
});

});

describe("returns false when", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Mermaid/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

const mermaidStart =
/^(\s*)(graph|flowchart|sequenceDiagram|classDiagram|stateDiagram|erDiagram|journey|gantt|pie|requirementDiagram|gitGraph|C4Context|C4Container|C4Component|C4Dynamic|C4Deployment|timeline)/;
/^(\s*)(graph|flowchart|sequenceDiagram|classDiagram|stateDiagram|erDiagram|journey|gantt|pie|requirementDiagram|gitGraph|C4Context|C4Container|C4Component|C4Dynamic|C4Deployment|timeline)/gm;

export const isMermaidCode = (code: string): boolean => {
if (code.startsWith('%%{init')) {
Expand Down

0 comments on commit 21d5b7f

Please sign in to comment.