simonhaenisch / md-to-pdf

Hackable CLI tool for converting Markdown files to PDF using Node.js and headless Chrome.
https://www.npmjs.com/md-to-pdf
MIT License
1.21k stars 110 forks source link

feature: Render inline mermaidjs blocks #124

Open humble-barnacle001 opened 2 years ago

humble-barnacle001 commented 2 years ago

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/

simonhaenisch commented 2 years ago

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 (:

humble-barnacle001 commented 2 years ago

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

danishcake commented 1 year ago

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?

simonhaenisch commented 1 year ago

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