Integrating Mermaid in Gitiles markdown renderer

433 views
Skip to first unread message

Réda Housni Alaoui

unread,
Sep 27, 2023, 6:49:58 AM9/27/23
to Repo and Gerrit Discussion
Hello everyone,

As part of the #gothenburg2023 hackaton, I'd like to integrate Mermaid into Gitiles.

Mermaid is a javascript program that converts a diagram text representation into an SVG representation. It is already supported by GitHub markdown renderer.

I took a look at Gitiles source code. Currently, Gitiles only performs markdown rendering on the server-side, therefore using java. 

I think there are multiple (naive?) solutions to add Mermaid to the Markdown rendering:
  1. the easiest: add Mermaid Npm Package to the browser-side to perform the mermaid FencedCodeBlock rendering on the browser-side
  2. use Puppeteer to execute Mermaid Npm Package on the server-side
  3. the hardest/highly unlikely: re-implement Mermaid in java
I think we should pick option 1.
But it seems that Gitiles was designed with browser-side security in mind. Currently, there isn't a single third party javascript module loaded by Gitiles. So I am not sure that integrating Mermaid Npm Package would be accepted by the community.
If we think that some people/organizations will refuse to reference a third party javascript library, I suggest 2 ways of implementing option 1:
  1. Adding a configuration flag controlling Mermaid activation. It would be disabled by default.
  2. Adding an extension point to Gitiles at https://gerrit.googlesource.com/gitiles/+/refs/heads/master/java/com/google/gitiles/doc/MarkdownToHtml.java#312
What do you think? Please share your suggestions/interrogations/observations !

Réda Housni Alaoui

unread,
Sep 28, 2023, 6:05:33 AM9/28/23
to Repo and Gerrit Discussion

Réda Housni Alaoui

unread,
Sep 28, 2023, 8:25:04 AM9/28/23
to Repo and Gerrit Discussion
I am not used to Bazel. I don't know where to start to add an npm dependency.
Should I add a Mermaid npm module dependency, or should I add https://github.com/mermaid-js/mermaid as a submodule? Is there any example of such frontend dependency I could take inspiration from?

Réda Housni Alaoui

unread,
Sep 28, 2023, 10:45:24 AM9/28/23
to Repo and Gerrit Discussion
Given the project already rely heavily on Maven Central, I am going to pull the dependency via https://www.webjars.org/ .

Vitaly Bordyug DE

unread,
Feb 2, 2024, 12:50:34 PM2/2/24
to Repo and Gerrit Discussion
Hi all,  

Sorry to pull out an old thread, just would be generally interested if anything came out of this initiative (even if it is not yet mergeable/buildable state)

TIA!

-Vitaly

Reply all
Reply to author
Forward
0 new messages