mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-08-31 22:26:53 +02:00
Disallow leading whitespace before delimiter
This commit is contained in:
@@ -500,11 +500,11 @@ describe('Class diagram V2', () => {
|
|||||||
it('1433: should render a simple class with a title', () => {
|
it('1433: should render a simple class with a title', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`---
|
`---
|
||||||
title: simple class diagram
|
title: simple class diagram
|
||||||
---
|
---
|
||||||
classDiagram-v2
|
classDiagram-v2
|
||||||
class Class10
|
class Class10
|
||||||
`,
|
`,
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -277,12 +277,12 @@ describe('Entity Relationship Diagram', () => {
|
|||||||
it('1433: should render a simple ER diagram with a title', () => {
|
it('1433: should render a simple ER diagram with a title', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`---
|
`---
|
||||||
title: simple ER diagram
|
title: simple ER diagram
|
||||||
---
|
---
|
||||||
erDiagram
|
erDiagram
|
||||||
CUSTOMER ||--o{ ORDER : places
|
CUSTOMER ||--o{ ORDER : places
|
||||||
ORDER ||--|{ LINE-ITEM : contains
|
ORDER ||--|{ LINE-ITEM : contains
|
||||||
`,
|
`,
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -666,11 +666,11 @@ flowchart RL
|
|||||||
it('1433: should render a titled flowchart with titleTopMargin set to 0', () => {
|
it('1433: should render a titled flowchart with titleTopMargin set to 0', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`---
|
`---
|
||||||
title: Simple flowchart
|
title: Simple flowchart
|
||||||
---
|
---
|
||||||
flowchart TD
|
flowchart TD
|
||||||
A --> B
|
A --> B
|
||||||
`,
|
`,
|
||||||
{ titleTopMargin: 0 }
|
{ titleTopMargin: 0 }
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -325,11 +325,11 @@ describe('Git Graph diagram', () => {
|
|||||||
it('1433: should render a simple gitgraph with a title', () => {
|
it('1433: should render a simple gitgraph with a title', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`---
|
`---
|
||||||
title: simple gitGraph
|
title: simple gitGraph
|
||||||
---
|
---
|
||||||
gitGraph
|
gitGraph
|
||||||
commit
|
commit
|
||||||
`,
|
`,
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -562,12 +562,12 @@ stateDiagram-v2
|
|||||||
it('1433: should render a simple state diagram with a title', () => {
|
it('1433: should render a simple state diagram with a title', () => {
|
||||||
imgSnapshotTest(
|
imgSnapshotTest(
|
||||||
`---
|
`---
|
||||||
title: simple state diagram
|
title: simple state diagram
|
||||||
---
|
---
|
||||||
stateDiagram-v2
|
stateDiagram-v2
|
||||||
[*] --> State1
|
[*] --> State1
|
||||||
State1 --> [*]
|
State1 --> [*]
|
||||||
`,
|
`,
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -17,9 +17,9 @@
|
|||||||
<h1>Class diagram demos</h1>
|
<h1>Class diagram demos</h1>
|
||||||
|
|
||||||
<pre class="mermaid">
|
<pre class="mermaid">
|
||||||
---
|
---
|
||||||
title: Demo Class Diagram
|
title: Demo Class Diagram
|
||||||
---
|
---
|
||||||
classDiagram
|
classDiagram
|
||||||
accTitle: Demo Class Diagram
|
accTitle: Demo Class Diagram
|
||||||
accDescr: This class diagram show the abstract Animal class, and 3 classes that inherit from it: Duck, Fish, and Zebra.
|
accDescr: This class diagram show the abstract Animal class, and 3 classes that inherit from it: Duck, Fish, and Zebra.
|
||||||
|
@@ -17,9 +17,9 @@
|
|||||||
<h2>Sample 1</h2>
|
<h2>Sample 1</h2>
|
||||||
<h3>graph</h3>
|
<h3>graph</h3>
|
||||||
<pre class="mermaid">
|
<pre class="mermaid">
|
||||||
---
|
---
|
||||||
title: This is a complicated flow
|
title: This is a complicated flow
|
||||||
---
|
---
|
||||||
graph LR
|
graph LR
|
||||||
accTitle: This is a complicated flow
|
accTitle: This is a complicated flow
|
||||||
accDescr: This is the descriptoin for the complicated flow.
|
accDescr: This is the descriptoin for the complicated flow.
|
||||||
@@ -224,9 +224,9 @@
|
|||||||
<h2>Sample 2</h2>
|
<h2>Sample 2</h2>
|
||||||
<h3>graph</h3>
|
<h3>graph</h3>
|
||||||
<pre class="mermaid">
|
<pre class="mermaid">
|
||||||
---
|
---
|
||||||
title: What to buy
|
title: What to buy
|
||||||
---
|
---
|
||||||
graph TD
|
graph TD
|
||||||
accTitle: What to buy
|
accTitle: What to buy
|
||||||
accDescr: Options of what to buy with Christmas money
|
accDescr: Options of what to buy with Christmas money
|
||||||
|
@@ -16,9 +16,9 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>Git diagram demo</h1>
|
<h1>Git diagram demo</h1>
|
||||||
<pre class="mermaid">
|
<pre class="mermaid">
|
||||||
---
|
---
|
||||||
title: Simple Git diagram
|
title: Simple Git diagram
|
||||||
---
|
---
|
||||||
gitGraph:
|
gitGraph:
|
||||||
options
|
options
|
||||||
{
|
{
|
||||||
|
@@ -16,9 +16,9 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>Journey diagram demo</h1>
|
<h1>Journey diagram demo</h1>
|
||||||
<pre class="mermaid">
|
<pre class="mermaid">
|
||||||
---
|
---
|
||||||
title: My working day
|
title: My working day
|
||||||
---
|
---
|
||||||
journey
|
journey
|
||||||
accTitle: Very simple journey demo
|
accTitle: Very simple journey demo
|
||||||
accDescr: 2 main sections: work and home, each with just a few tasks
|
accDescr: 2 main sections: work and home, each with just a few tasks
|
||||||
|
@@ -17,9 +17,9 @@
|
|||||||
<h1>State diagram demos</h1>
|
<h1>State diagram demos</h1>
|
||||||
<h2>Very simple showing change from State1 to State2</h2>
|
<h2>Very simple showing change from State1 to State2</h2>
|
||||||
<pre class="mermaid">
|
<pre class="mermaid">
|
||||||
---
|
---
|
||||||
title: Very simple diagram
|
title: Very simple diagram
|
||||||
---
|
---
|
||||||
stateDiagram
|
stateDiagram
|
||||||
accTitle: This is the accessible title
|
accTitle: This is the accessible title
|
||||||
accDescr:This is an accessible description
|
accDescr:This is an accessible description
|
||||||
@@ -46,9 +46,9 @@
|
|||||||
</code>
|
</code>
|
||||||
</p>
|
</p>
|
||||||
<pre class="mermaid">
|
<pre class="mermaid">
|
||||||
---
|
---
|
||||||
title: Very simple diagram
|
title: Very simple diagram
|
||||||
---
|
---
|
||||||
stateDiagram-v2
|
stateDiagram-v2
|
||||||
accTitle: This is the accessible title
|
accTitle: This is the accessible title
|
||||||
accDescr: This is an accessible description
|
accDescr: This is an accessible description
|
||||||
|
@@ -41,6 +41,13 @@ describe('extractFrontmatter', () => {
|
|||||||
expect(db.setDiagramTitle).toHaveBeenCalledWith('foo---bar');
|
expect(db.setDiagramTitle).toHaveBeenCalledWith('foo---bar');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('handles frontmatter with multi-line string and multiple delimiters', () => {
|
||||||
|
const db = dbMock();
|
||||||
|
const text = `---\ntitle: |\n multi-line string\n ---\n---\ndiagram`;
|
||||||
|
expect(extractFrontMatter(text, db)).toEqual('diagram');
|
||||||
|
expect(db.setDiagramTitle).toHaveBeenCalledWith('multi-line string\n---\n');
|
||||||
|
});
|
||||||
|
|
||||||
it('handles frontmatter with title', () => {
|
it('handles frontmatter with title', () => {
|
||||||
const db = dbMock();
|
const db = dbMock();
|
||||||
const text = `---\ntitle: foo\n---\ndiagram`;
|
const text = `---\ntitle: foo\n---\ndiagram`;
|
||||||
|
@@ -6,7 +6,7 @@ import * as yaml from 'js-yaml';
|
|||||||
// Note that JS doesn't support the "\A" anchor, which means we can't use
|
// Note that JS doesn't support the "\A" anchor, which means we can't use
|
||||||
// multiline mode.
|
// multiline mode.
|
||||||
// Relevant YAML spec: https://yaml.org/spec/1.2.2/#914-explicit-documents
|
// Relevant YAML spec: https://yaml.org/spec/1.2.2/#914-explicit-documents
|
||||||
export const frontMatterRegex = /^(?:\s*---\s*[\r\n])(.*?)(?:[\r\n]\s*---\s*[\r\n]+)/s;
|
export const frontMatterRegex = /^(?:---\s*[\r\n])(.*?)(?:[\r\n]---\s*[\r\n]+)/s;
|
||||||
|
|
||||||
type FrontMatterMetadata = {
|
type FrontMatterMetadata = {
|
||||||
title?: string;
|
title?: string;
|
||||||
|
@@ -238,10 +238,9 @@ Alice->Bob: hi`;
|
|||||||
const type = detectType(str);
|
const type = detectType(str);
|
||||||
expect(type).toBe('gitGraph');
|
expect(type).toBe('gitGraph');
|
||||||
});
|
});
|
||||||
it('should handle frontmatter with leading spaces', function () {
|
it('should not allow frontmatter with leading spaces', function () {
|
||||||
const str = ' ---\ntitle: foo\n---\n gitGraph TB:\nbfs1:queue';
|
const str = ' ---\ntitle: foo\n---\n gitGraph TB:\nbfs1:queue';
|
||||||
const type = detectType(str);
|
expect(() => detectType(str)).toThrow('No diagram type detected for text');
|
||||||
expect(type).toBe('gitGraph');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('when finding substring in array ', function () {
|
describe('when finding substring in array ', function () {
|
||||||
|
Reference in New Issue
Block a user