johanneswuerbach / markdown-inline-mermaid

Render inline graphs with Markdown and Mermaid
MIT License
9 stars 2 forks source link

Exclude lines from being rendered #4

Open zinizhu opened 3 months ago

zinizhu commented 3 months ago

I am wondering if there's a way to exclude a stanza from being transformed to mermaid diagram? Sometimes we want to show people how to create a mermaid diagram with markdown. The markdown source code is like:

An example Mermaid diagram source code can be like:

````text
```mermaid
graph LR
  A[Start] --> B{Error?};
  B -->|Yes| C[Hmm...];
  C --> D[Debug];
  D --> B;
  B ---->|No| E[Yay!];

And this will be rendered as:
```mermaid
graph LR
  A[Start] --> B{Error?};
  B -->|Yes| C[Hmm...];
  C --> D[Debug];
  D --> B;
  B ---->|No| E[Yay!];


And we are getting:

<img width="875" alt="Screenshot 2024-04-01 at 14 27 14" src="https://github.com/johanneswuerbach/markdown-inline-mermaid/assets/31359639/f81501eb-5985-433a-90d7-52edba000ef8">

Ideally we don't want the mermaid code under ````text block to be transformed.

Is there a way to exclude that stanza from being transformed? 
johanneswuerbach commented 1 week ago

Currently not, I guess you would need to tweak the regex https://github.com/johanneswuerbach/markdown-inline-mermaid/blob/main/markdown_inline_mermaid.py#L30 to consider this case.