What exactly trigger MermaidJS diagrams rendering ? #8000
-
I'm working on a printed version of my documentation site and need to render all content before generating the final document. This includes elements like MermaidJS, MathJax, content tabs, admonitions, and others. For most of these, I can use a headless browser to load the page, allowing the JavaScript scripts to execute and transform the content as expected. However, MermaidJS is the only one that does not render during this process. Instead of generating diagrams, the document retains the raw MermaidJS code. Upon inspecting the mkdocs-material code, I noticed that all TypeScript files are bundled into an IIFE (Immediately Invoked Function Expression), which means I can't directly access them. However, when I manually copy the JavaScript function responsible for rendering MermaidJS diagrams into a separate JS file, my headless browser successfully renders the diagrams. I want to understand:
I'm not sure if i understood the typescript code and bundling process correctly so i could be wrong in my research. Any help would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi @Thiti517, However, Mermaid is mounted in a closed ShadowRoot, so depending on how you detect that an element is available on the website, then the separate root layer might prevent that: |
Beta Was this translation helpful? Give feedback.
Hi @Thiti517,
please elaborate on the "render all content before generating the final document". Mermaid is mounted like the rest of the elements:
mkdocs-material/src/templates/assets/javascripts/components/content/_/index.ts
Line 117 in 44c3b56
However, Mermaid is mounted in a closed ShadowRoot, so depending on how you detect that an element is available on the website, then the separate root layer might prevent that:
mkdocs-material/src/templates/assets/javascripts/components/content/mermaid/index.ts
Line 119 in 44c3b56