md-to-pdf icon indicating copy to clipboard operation
md-to-pdf copied to clipboard

feature: Render inline mermaidjs blocks

Open humble-barnacle001 opened this issue 2 years ago • 4 comments

Problem:

Render the mermiadjs block like Github. For example:

sequenceDiagram
    Alice->>+John: Hello John, how are you?
    Alice->>+John: John, can you hear me?
    John-->>+Alice: Hi Alice, I can hear you!
    John-->>-Alice: I feel great!

renders to

sequenceDiagram
    Alice->>+John: Hello John, how are you?
    Alice->>+John: John, can you hear me?
    John-->>+Alice: Hi Alice, I can hear you!
    John-->>-Alice: I feel great!

Solution:

https://github.blog/2022-02-14-include-diagrams-markdown-files-mermaid/

humble-barnacle001 avatar Apr 25 '22 07:04 humble-barnacle001

Basically same as https://github.com/simonhaenisch/md-to-pdf/issues/41#issuecomment-520246228: it's possible to do this via a marked extension (see https://marked.js.org/using_pro).

If you happen to figure out how to do this, please let us know here (:

simonhaenisch avatar Apr 26 '22 08:04 simonhaenisch

I wanted the feature for a school assignment of mine.

If you happen to figure out how to do this, please let us know here (:

Right now I am little busy with school work but as soon as I am free I shall try to make it work eta 1 month

humble-barnacle001 avatar Apr 26 '22 11:04 humble-barnacle001

So, I had a crack at this recently. It shouldn't be too hard, theoretically, but it took a bit of persuading for mermaid to actually render. See the gist below.

https://gist.github.com/danishcake/d045c867594d6be175cb394995c90e2c

The gotcha was that mermaid.initialize() didn't trigger the render. I had to explicitly call mermaid.run. I'm not sure why.

Given this is a semi-common request, perhaps something like the above could be rolled into the documentation, or a set of pre-packaged (but optional) extensions?

danishcake avatar Sep 19 '23 06:09 danishcake

i proposed turning this into a marked extension in #145 (: sadly i don't have the time to work on it

simonhaenisch avatar Sep 19 '23 12:09 simonhaenisch