-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrate Mermaid.js
diagramming and graphing tool
#2701
Comments
See also issue #936. |
Technically, we'd need to call
.. gets rendered into html as the following (note the
|
Ideally, we wouldn't insert the Either we look for code blocks tagged as mermaid, or we have a brew.metadata field for Probably the former for the simplest user experience. |
Making this work on Making this work in the editor preview pane is going to be painful, especially since our app scrubs/dumps the html dom and replaces with fresh renders on every edit. As a minimum viable product (MVP: a product with enough features to attract early-adopter customers and validate a product idea), we'd implement only on |
We can probably just make a Marked.js extension that does this so pages don't need to individually import the Mermaid script. For instance the Mermaid docs show one way of doing it. https://mermaid.js.org/config/usage.html#example-of-a-marked-renderer Marked has since evolved so we can do it as a separate extension (a separate NPM package so others can benefit) instead of trying to cram it in with our existing custom renderer stuff. |
Part of the pain I allude to here is the processing time — we probably don't want Mermaid re-parsing/rendering on every keystroke of editing. The Mermaid live editor demo has a useful UI widget |
Another thing to consider, if we make it a Marked.js extension, is we can probably change the container syntax somewhat. For example replace the ````mermaid` with something else more "user-friendly" (most would have no idea what "mermaid" means). Regardless, @MichielDeMey does your working model use a Marked.js extension? I'm hoping to eventually convert all of our weird custom Markdown stuff into proper extension packages to make them easier to maintain. You can see an example of how we extended Tables to support column and row spanning: https://github.com/calculuschild/marked-extended-tables |
Possibly disagree. Writing these "mermaid" code blocks requires being familiar with the mermaid code standards, said syntax being available at the mermaid website. We're going to point them in that direction anyway. At best (if using some new term) we solve the problem of "how do I draw flowcharts and timelines?" by answering "use a code bock tagged with On the other hand, leaving it as |
That's great (and fast!). Does it regenerate all mermaid svgs every time the preview pane is updated? Definitely agree a minimum style would be ideal. We could roll it out without that themed CSS though (and keep it unannounced) — that way those in the know can experiment with styles. |
Mmmm... Good point. |
Some info for minimal styling, particularly looking at official examples: There's some styling on this Reddit post - https://www.reddit.com/r/homebrewery/comments/gfapc2/suggestions_adventure_flowchart Some examples from Waterdeep: Dungeon of the Mad Mage here - #936 (comment) Here's a couple from Baldur's Gate: Descent into Avernus that I had on Imgur for reasons: |
Weighing in on the discussion here:
Agreed. Whilst Mermaid syntax might frighten some casual users, it IS easy to learn and there are a lot of great resources online to learn about it. Realistically, looking at some of the adventure flowcharts in the source books it's really nothing more than a linear path. We can add a simple example to the Homebrewery kitchensink and we'll have helped 90% of the casual users.
Yes, I'm developing a generic Marked.js extension so that we can simply
The marked result is simply memoized, so it will only regenerate the specific Mermaid SVG when the source code of that specific block changes. In practice, I've not noticed a performance drop, however we could optimize the caching behaviour down the road if we notice that users start to use a lot of Mermaid graphs. Let me know if you have any more questions. |
This might be due to fonts not being fully loaded when mermaid is invoked — IIRC there's a specific mention of the issue on the mermaid website (possibly when discussing icon fonts). |
Do you have a PR for this? I can take a look. |
@calculuschild I've pushed my code and created a WIP PR for people to play with: #2740 |
I reimplemented this in 3697. There are still things preventing it from coming all the way forward. It appears that the marked plugin code rollup isn't compatible with the I will try moving this internal to markdown.js to see if that solves the issue. |
Your idea:
TL;DR:
Write into your brew a code block using their [relatively] simple text syntax
and this magically appears:
There are multiple diagram types (flowchart, gantt, pie, etc), and each can also be styled visually via css.
In terms of coding to support this .. at it's simplest we just insert a
<script>
element (which scans the page looking for code blocks with a particular classname), that's pretty much it [technically, there's more — I'm saying we don't need to do anything complicated with rejigging the parser or renderer].The text was updated successfully, but these errors were encountered: