-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Description
Description
The class diagram renderer throws a Syntax error in text when attempting to define a class with an inline nested generic type (e.g., class People ListListPerson~~). Additionally, the parser in version 11.13.0 struggles to differentiate between nested generic closings (~~) and markdown strike-through tokens, leading to a rendering crash in the classchart.html demo file.
Steps to reproduce
-
Open the packages/mermaid/demos/classchart.html file in the development environment.
-
Navigate to the Person and People class diagram section.
-
Observe that the diagram fails to render, showing a "Syntax error in text" message.
-
Note that the error occurs immediately after the Fruit namespace diagrams.
Screenshots
Before:
After:
Code Sample
<!-- Original broken code -->
<pre class="mermaid">
classDiagram
class Person {
+ID : Guid
+FirstName : string
+LastName : string
-privateProperty : string
#ProtectedProperty : string
~InternalProperty : string
~AnotherInternalProperty : List~List~string~~
}
class People List~List~Person~~
</pre>
<hr />
<pre class="mermaid">
classDiagram
namespace Company.Project.Module {
class GenericClass~T~ {
+addItem(item: T)
+getItem() T
}
}
</pre>
<!-- Fixed code -->
<pre class="mermaid">
classDiagram
class Person {
+ID : Guid
+FirstName : string
+LastName : string
-privateProperty : string
#ProtectedProperty : string
~InternalProperty : string
~AnotherInternalProperty : List~List~string~ ~
}
class People {
+List~List~Person~~ members
}
</pre>
<hr />
<pre class="mermaid">
classDiagram
namespace Company.Project.Module {
class GenericClass~T~ {
+addItem(item: T)
+getItem() : T
}
}
</pre>
Setup
Mermaid Version: 11.13.0
Browser: (Chrome
OS: Windows
Suggested Solutions
The issue was caused by the parser's inability to handle the space-separated class alias on a single line.
-
Class Definition: Changed class People List
ListPerson~~ to a standard block definition class People { ... }. -
Generic Tokenization: Added a whitespace between nested tildes (~ ~) in AnotherInternalProperty to prevent the parser from misinterpreting the closing generics as a strike-through symbol.
-
Method Syntax: Added missing colons to method return types ( +getItem() : T) to comply with the stricter Langium parser requirements in the current monorepo.
Additional Context
This error was identified while testing the classchart.html file within the monorepo using pnpm run dev. Fixing these syntax triggers allows the full suite of demo diagrams to render correctly.