Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Will generate the following Mermaid output:

```mermaid
---
title: Basic usage
title: "Basic usage"
---
flowchart TD
start["Start"]
Expand Down Expand Up @@ -183,7 +183,7 @@ Will generate the following Mermaid output:

```mermaid
---
title: Various node shapes
title: "Various node shapes"
---
flowchart TD
rectangle["Rectangle"]
Expand Down Expand Up @@ -247,7 +247,7 @@ Will generate the following Mermaid output:

```mermaid
---
title: Link types
title: "Link types"
---
flowchart TD
a["A"]
Expand Down Expand Up @@ -308,7 +308,7 @@ Will generate the following Mermaid output:

```mermaid
---
title: Using subgraphs
title: "Using subgraphs"
---
flowchart TD
n["Node"]
Expand Down Expand Up @@ -373,7 +373,7 @@ Will generate the following Mermaid output:

```mermaid
---
title: Styling nodes
title: "Styling nodes"
---
flowchart TD
a["A"]
Expand Down Expand Up @@ -427,7 +427,7 @@ Will generate the following Mermaid output:

```mermaid
---
title: Styling links
title: "Styling links"
---
flowchart TD
a["A"]
Expand Down
4 changes: 2 additions & 2 deletions src/Mermaid.Flowcharts/FlowchartTitle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static FlowchartTitle FromString(string text)
throw new ArgumentException("Flowchart title must not be whitespace.", nameof(text));
}

return new(text);
return new(text.Replace("\"", "\\\""));
}

public override string ToString()
Expand All @@ -43,7 +43,7 @@ public string ToMermaidString(int indentations = 0, string indentationText = "
StringBuilder flowchartTitleBuilder = new();
flowchartTitleBuilder
.AppendLine($"{indentationText.Repeat(indentations)}---")
.AppendLine($"{indentationText.Repeat(indentations)}title: {Text}")
.AppendLine($"{indentationText.Repeat(indentations)}title: \"{Text}\"")
.Append($"{indentationText.Repeat(indentations)}---");
return flowchartTitleBuilder.ToString();
}
Expand Down
16 changes: 8 additions & 8 deletions src/Mermaid.Flowcharts/Nodes/NodeIdentifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ public static NodeIdentifier Create()

public static NodeIdentifier FromString(string text)
{
if (text.StartsWith('_') || text.StartsWith('.') || text.StartsWith('-'))
if (string.IsNullOrEmpty(text))
{
throw new ArgumentException("Identifier must not start with a separator.", nameof(text));
throw new ArgumentException("Identifier must not be empty.", nameof(text));
}

if (text.EndsWith('_') || text.EndsWith('.') || text.EndsWith('-'))
if (string.IsNullOrWhiteSpace(text))
{
throw new ArgumentException("Identifier must not end with a separator.", nameof(text));
throw new ArgumentException("Identifier must not be whitespace.", nameof(text));
}

if (string.IsNullOrEmpty(text))
if (text.StartsWith('_') || text.StartsWith('.') || text.StartsWith('-'))
{
throw new ArgumentException("Identifier must not be empty.", nameof(text));
throw new ArgumentException("Identifier must not start with a separator.", nameof(text));
}

if (string.IsNullOrWhiteSpace(text))
if (text.EndsWith('_') || text.EndsWith('.') || text.EndsWith('-'))
{
throw new ArgumentException("Identifier must not be whitespace.", nameof(text));
throw new ArgumentException("Identifier must not end with a separator.", nameof(text));
}

bool containsDisallowedValue = text.AsSpan().IndexOfAnyExcept(AllowedCharacters) > -1;
Expand Down
21 changes: 19 additions & 2 deletions tests/Mermaid.Flowcharts.Tests/FlowchartTitleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@ public void Title_ShouldThrow_WhenNewline(string newline)
'a',
"""
---
title: a
title: "a"
---
""")]
[InlineData(
'"',
"""
---
title: "\""
---
""")]
public void Title_ShouldToMermaidString_SingleLetter(char letter, string expected)
Expand All @@ -98,7 +105,17 @@ public void Title_ShouldToMermaidString_SingleLetter(char letter, string expecte
" ",
"""
---
title: a
title: "a"
---
"""
)]
[InlineData(
'"',
2,
" ",
"""
---
title: "\""
---
"""
)]
Expand Down
12 changes: 6 additions & 6 deletions tests/Mermaid.Flowcharts.Tests/ReadmeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void BasicUsage()
string expected =
"""
---
title: Basic usage
title: "Basic usage"
---
flowchart TD
start["Start"]
Expand Down Expand Up @@ -98,7 +98,7 @@ public void VariousNodeShapes()
string expected =
"""
---
title: Various node shapes
title: "Various node shapes"
---
flowchart TD
rectangle["Rectangle"]
Expand Down Expand Up @@ -156,7 +156,7 @@ public void LinkTypes()
string expected =
"""
---
title: Link types
title: "Link types"
---
flowchart TD
a["A"]
Expand Down Expand Up @@ -210,7 +210,7 @@ public void UsingSubgraphs()
string expected =
"""
---
title: Using subgraphs
title: "Using subgraphs"
---
flowchart TD
n["Node"]
Expand Down Expand Up @@ -258,7 +258,7 @@ public void StylingNodes()
string expected =
"""
---
title: Styling nodes
title: "Styling nodes"
---
flowchart TD
a["A"]
Expand Down Expand Up @@ -306,7 +306,7 @@ public void StylingLinks()
string expected =
"""
---
title: Styling links
title: "Styling links"
---
flowchart TD
a["A"]
Expand Down