mermaid-js / mermaid

Generation of diagrams like flowcharts or sequence diagrams from text in a similar manner as markdown
https://mermaid.js.org
MIT License
72.82k stars 6.66k forks source link

Multi-line Comments #4518

Closed nirname closed 1 year ago

nirname commented 1 year ago

Proposal

We need to support multi-line comments, currently they are not supported.

I suggest a syntax like this %{ }%, which has to be discussed.

Escape character for titles and captions with special characters has yet to be discussed too. Perhaps double percent %% can be replaced with % in resulting diagram.

Example

A complete example is:

myGraph
%% one line comment
Bob -> Hello -> Alice %% trailing comment
%{
multi-line
comment
}%
Pete -> Hello %{ comment in the middle }% -> Alice
Steve -> Hello %{
multi-line
comment
in the middle
}% -> Alice

It should be possible to have it inserted in the middle of the string:

a -> b %{ comment }% -> c

It can start on any line and end on any line too:

a-> b %{
long
comment
}% -> c

the result should be:

a -> b  -> c

Note, there are 2 spaces between b and following arrow, they are representing the idea that after comment is deleted everything else stays intact.

One line comment should be treated as trailing comment, so everything that start with %% till the end of the line is a comment.

The %%, %{ and %} symbols are treated as parts of the comments too.

Comments should be removed before graph parsing.

Taking that in consideration, no graphs should have these symbols in their's grammars. If someone needs to include a line containing any of those inside a caption, label or a title he must precede it with escape character. The most common techniques about that is

Screenshots

No response

nirname commented 1 year ago

I have not found a separate bug for it, but trailing comments are not working right now

Yokozuna59 commented 1 year ago

there is an issue for it #1281, it has been implemented then reverted, an not open again

Yokozuna59 commented 1 year ago

I'm voting to that syntax, I've already implemented here but the parser is not done

https://github.com/mermaid-js/mermaid/blob/058b08d9b62b06d34f6fcdedb29c8a72fa21521f/packages/parser/src/language/grammars/common.langium#L12

nirname commented 1 year ago

I think i have to close this issue, because it is a duplicate of this one