Mermaid JS Plugin

Repo: GitHub - unfoldingWord/discourse-mermaid: Adds the Mermaid JS library to discourse · GitHub

Overview

This plugin adds the Mermaid JS library to Discourse so that posts can make use of its features. It turns this:

[mermaid]
gantt
    title A Gantt Diagram
    dateFormat  YYYY-MM-DD
    section Section
    A task           :a1, 2014-01-01, 30d
    Another task     :after a1  , 20d
    section Another
    Task in sec      :2014-01-12  , 12d
    another task      : 24d
[/mermaid]

into this:

See the Mermaid JS site for documentation and more examples.

Installation

The installation notes are available at GitHub - unfoldingWord/discourse-mermaid: Adds the Mermaid JS library to discourse · GitHub (in short, just add it to app.yml).

Notes

Thanks to @j.jaffeux, version 0.0.3 of this plugin is much easier to install and the generated charts load reliably and immediately.

30개의 좋아요

This is very cool, some ideas for future work:

  1. email support here is going to be ultra weak cause it is likely to require very rich feature from email that you can not deliver

I would recommend adding a reduce_cooked email hook (see discourse/lib/pretty_text.rb at 4ad924bcf5acb6c99868887b2a402b7b5f289771 · discourse/discourse · GitHub ) you can use image magick to convert SVG to an image, create an upload, tie to post and then add it there. It is fiddly but would add value.

  1. This hack is interesting, cause you could make this wider and support graphviz GitHub - mdaines/viz-js: Graphviz in your browser · GitHub
11개의 좋아요

Can’t you vendor this lib so a user can skip this step? I believe GitHub - discourse/discourse-math: Official MathJax support for Discourse · GitHub does this.

11개의 좋아요

I’d love to, especially because I’m suspicious that might make the rendering more reliable. However, I can’t see how this happens, can you point me to something more specific?

Hi @jag3773,

I made a PR to this plugin project. It’s now fully lazy loaded and you don ’t need to add anything in your header. Enjoy!

https://github.com/unfoldingWord-dev/discourse-mermaid/pull/1

13개의 좋아요

Thanks @j.jaffeux ! As you saw, I merged in your PR and the results are far superior. The charts now load reliably and nearly instantly. I’ve updated the OP along these lines.

7개의 좋아요

Really love this plugin, it is very fun to use when you get instant updates in the editor preview pane :smiley:
Is there an easy way to make the plugin work better with dark themes?

There seems to be some example css in https://github.com/knsv/mermaid/tree/master/src/themes but I’m not sure what parts of it I would need to copy over to the theme CSS to make it the default for charts

Right now it looks like this with the bundled Dark theme, I would like to at least make all text and arrows white :

3개의 좋아요

I’ll add one more thing to my wishlist, it would be great to have a composer button for Mermaid that could insert some example charts and have a link to the documentation site to make it easier for new users to discover all the functionality of the script.

I started looking for a generic toolbar customizer plugin to insert the snippets I need but it doesn’t look like anyone has made one. It would probably make more sense for each plugin to manage their own toolbar extensions anyway.

1개의 좋아요

I totally agree, the instant updates in the preview pane are awesome!

I see how it doesn’t look great with the Dark theme :frowning: . Unfortunately, I don’t have the know how or capacity to work on a fix for that. However, I would gladly accept a PR that introduces a solution.

Node styling, as described in https://mermaidjs.github.io/flowchart.html does work. But that may be of limited usefulness in addressing the Dark theme issue.

Mermaid has a few themes in their repo, which I imagine you’d be able to select either with a site setting or something. My wild guess would be that this turns into

mermaid.init({ theme: 'dark' }, $mermaid)

Unfortunately none of the current ones (options are ‘dark’, ‘forest’, and ‘neutral’) really look good with DIscourse’s dark theme (they all have black text labels), so my recommendation here for someone willing to work on this (not me sorry :mermaid:)

Is it possible to support the render of the chart while printing (via ctrl+p) when using this mermaid plugin?

Simplest would be just to use the graphviz plugin instead

4개의 좋아요

@sam Thanks for the link

플러그인 감사합니다! 디스코urs 팀에게 매우 유용합니다.

1개의 좋아요

@rishabhlakhotia (Github) 덕분에 mermaidJS를 v8.10.1로 갱신했습니다.

4개의 좋아요

플로우차트에서 일부 텍스트가 올바른 형식으로 표시되지 않습니다.
특히 ``를 사용하여 포맷팅이 필요할 때 그렇습니다:

"`The **cat**  in the hat`"

mermaid.live에서는 모두 정상적으로 동작합니다.
이 샘플에 대한 테스트입니다:

flowchart LR
subgraph "One"
  a("`The **cat**
  in the hat`") -- "edge label" --> b{{"`The **dog** in the hog`"}}
end
subgraph "`**Two**`"
  c("`The **cat**
  in the hat`") -- "`Bold **edge label**`" --> d("The dog in the hog")
end

문서 Flowcharts Syntax | Mermaid 에서 확인했습니다.

메타에서는 플러그인이 아니라 테마 컴포넌트인 Discourse Mermaid 를 사용하고 있으며, 해당 예제를 사용하여 유사한 결과를 확인할 수 있습니다:

flowchart LR
subgraph "One"
  a("`The **cat**
  in the hat`") -- "edge label" --> b{{"`The **dog** in the hog`"}}
end
subgraph "`**Two**`"
  c("`The **cat**
  in the hat`") -- "`Bold **edge label**`" --> d("The dog in the hog")
end

그러나 링크된 예제는 완성된 플로우차트에 볼드/이탤릭 텍스트가 표시되지 않는 것 같아 따라가기가 어렵습니다: (마크다운 자체는 표시되지 않음)

확인해 보겠습니다. :slight_smile:

1개의 좋아요

감사합니다. 이제 테마 컴포넌트를 사용하도록 변경하겠습니다.

최고의 샘플을 확인하고 싶다면 다음 주소를 통해 테스트해 보세요:

2개의 좋아요