Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax error was observed if class diagram contains comment syntax with curly bracket like %%{ #1968

Closed
tomoyukim opened this issue Mar 28, 2021 · 2 comments
Labels
Contributor needed Graph: Class Status: Approved Is ready to be worked on Type: Bug / Error Something isn't working or is incorrect

Comments

@tomoyukim
Copy link

tomoyukim commented Mar 28, 2021

Describe the bug
I found syntax error is occurred if class diagram has comment syntax with curly brace like %%{. This was originally reported on tomoyukim/vscode-mermaid-editor#35 and I could reproduced on live editor as well. Please take a look at screenshot.

To Reproduce
Steps to reproduce the behavior:

  1. Try to render class diagram including %%{

For example,

classDiagram
	%%{
	Animal <|-- Duck
	Animal <|-- Fish
	Animal <|-- Zebra
	Animal : +int age
	Animal : +String gender
	Animal : +String sample
	Animal: +isMammal(a)
	Animal: +mate()
	class Duck{
		+String beakColor
		+swim()
		+quack()
	}
	class Fish{
		-int sizeInFeetaaaa
		-canEat()
	}
	class Zebra{
		+bool is_wild
		+run()
	}

Expected behavior
class diagram should be previewed.

Screenshots
Screen Shot 2021-03-28 at 22 16 35

Additional context
This was not observed on erDiagram at least.

@tomoyukim tomoyukim added Status: Triage Needs to be verified, categorized, etc Type: Bug / Error Something isn't working or is incorrect labels Mar 28, 2021
@jgreywolf jgreywolf added Contributor needed Graph: Class Status: Approved Is ready to be worked on and removed Status: Triage Needs to be verified, categorized, etc labels Apr 28, 2021
@NeilCuzon
Copy link
Member

NeilCuzon commented May 1, 2021

The syntax is that of a directive, which is a method of changing the diagram's rendering configuration.
I would refrain from using "%%{" or "}%%", unless you intend to use them for directives.

Example below changes theme to dark:
%%{init: { "theme": "dark" }}%%
classDiagram
Animal <|-- Duck
Animal <|-- Fish
Animal <|-- Zebra
Animal : +int age
Animal : +String gender
Animal: +isMammal()
Animal: +mate()
class Duck{
+String beakColor
+swim()
+quack()
}
class Fish{
-int sizeInFeet
-canEat()
}
class Zebra{
+bool is_wild
+run()
}

@NeilCuzon
Copy link
Member

I have added this to the documentation and will be more visible to users. Thanks for the contribution we really appreciate it, with that I will close this issue.

https://github.com/mermaid-js/mermaid/blob/master/docs/n00b-syntaxReference.md#diagram-breaking

@github-actions github-actions bot locked and limited conversation to collaborators May 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Contributor needed Graph: Class Status: Approved Is ready to be worked on Type: Bug / Error Something isn't working or is incorrect
Projects
None yet
Development

No branches or pull requests

3 participants