Skip to content
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

Offline/SSR rendering of Mermaid diagrams #8299

Open
1 of 2 tasks
matevz opened this issue Nov 8, 2022 · 5 comments
Open
1 of 2 tasks

Offline/SSR rendering of Mermaid diagrams #8299

matevz opened this issue Nov 8, 2022 · 5 comments
Labels
feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.

Comments

@matevz
Copy link

matevz commented Nov 8, 2022

Have you read the Contributing Guidelines on issues?

Description

The mermaid plugin in the recent Docusaurus 2.2.0 release works on the client-side only. Add support for rendering mermaid graphs offline while building the static site.

Has this been requested on Canny?

No response

Motivation

In some cases (e.g. scraping the website, disabled javascript in the client's browser, avoidance of repositioning/flickering esp. on mobile phones) it would be useful to render the diagrams into .svg resources while building the static site already and then only serve static images.

API design

No response

Have you tried building it?

No response

Self-service

  • I'd be willing to contribute this feature to Docusaurus myself.
@matevz matevz added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. status: needs triage This issue has not been triaged by maintainers labels Nov 8, 2022
@slorber slorber removed the status: needs triage This issue has not been triaged by maintainers label Nov 9, 2022
@slorber
Copy link
Collaborator

slorber commented Nov 9, 2022

Hey

Unfortunately, this is a known limitation that I'm aware of, and it's not easy to solve this in an efficient way.


Note even GitHub doesn't support Mermaid without JS:

graph TD;
    A-->B;
    A-->C;
    B-->D;
    C-->D;

Displays without JS:

CleanShot 2022-11-09 at 17 04 38@2x

@slorber slorber changed the title Offline rendering of mermaid diagrams Offline/SSR rendering of Mermaid diagrams Nov 9, 2022
@Airkro
Copy link

Airkro commented Nov 11, 2022

For now, mermaid SSR needs to run a browser instance or use online services.

Many remark plugins can do that: https://www.npmjs.com/search?ranking=maintenance&q=remark%20mermaid

You can integrate one of them into the docusaurus.

In my case, I using Kroki / https://github.com/nice-move/remark-kroki to do that.

@slorber
Copy link
Collaborator

slorber commented Nov 17, 2022

Users can already add remark plugins if they want this.

I'd rather let user use all these things in userland and provide feedback on what works best - before introducing anything relying on a headless browser in core.

@matevz
Copy link
Author

matevz commented Nov 17, 2022

FYI how we're currently attacking this problem is having diagrams in separate .mmd files and then use mmdc to generate the corresponding .svg files. Those are then referenced in the markdown as ordinary images. Our approach works, but involves some additional checks in CI so that the .svg files are always up-to-date with the original .mmd. Also, since the images are static svg's, switching to dark theme requires separate .svg files.

@slorber
Copy link
Collaborator

slorber commented Nov 10, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.
Projects
None yet
Development

No branches or pull requests

3 participants