johanneswuerbach / backstage-plugin-techdocs-addon-mermaid

Backstage TechDocs Mermaid Addon
MIT License
43 stars 18 forks source link

Mermaid diagram not detected if it starts with a comment #46

Closed kunickiaj closed 1 week ago

kunickiaj commented 2 months ago

The regex used to match the start of a mermaid diagram doesn't work if there are comments at the beginning of a diagram.

For example:

```mermaid
%% Debug using mermaid.live
flowchart TD
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D[Laptop]
    C -->|Two| E[iPhone]
    C -->|Three| F[fa:fa-car Car]


Modifying it to the following may fix the issue

`const mermaidStart =
  /(?:%%[^\n]*\n)*\s*(graph|flowchart|sequenceDiagram|classDiagram|stateDiagram|erDiagram|journey|gantt|pie|requirementDiagram|gitGraph|C4Context|C4Container|C4Component|C4Dynamic|C4Deployment|timeline)/;`
johanhammar commented 1 week ago

This should have been fixed in 0.12.1 by https://github.com/johanneswuerbach/backstage-plugin-techdocs-addon-mermaid/pull/52