Skip to content

new feature: stacking several contexts at the same time + Mermaid syntax

The new syntax context="name1!name2##SH!name3" allows multiple contexts to be stacked.

This syntax avoids the multiplication of contexts when a common syntax precedes a particular syntax.

For example, strings (single quote or double quote) in () or [] require the definition of four string contexts:

  • single quote + ]
  • double quote + ]
  • single quote + )
  • double quote + )

Which is represented by the following graph:

"[" -> SqStr1 -> "]"
    \> DqStr1 /
"(" -> SqStr2 -> ")"
    \> DqStr2 /

By stacking the closure before SqStr or DqStr, it is possible to reduce the number of contexts by jumping over the closure via a #pop.

"[" -> SqStr -> "]"
    \> DqStr /
"(" -> SqStr -> ")"
    \> DqStr /

Line 73 of mermaid.xml:

<context name="Flowchart_AfterNode" attribute="Normal" lineEndContext="#pop">
        <!-- [[...]] -->
        <StringDetect String="[[" attribute="Symbol"
                      context="Flowchart_TextNode_End[[]]!Flowchart_TextNode"/>
        <!-- [(...)] -->
        <StringDetect String="[(" attribute="Symbol"
                      context="Flowchart_TextNode_End[()]!Flowchart_TextNode"/>
        etc

I used ! because it is also the #pop/context separator and there is no conflict. But we could consider using !! to further reduce the risk. It is possible to base it on the version number, but I am not in favor of that.

Impact on performance: approximately 1.5% when measured with highlighter_benchmark.

FEATURE: 494286

Edited by jonathan poelen

Merge request reports

Loading