feat: add mermaid graphs rendering#48
Conversation
Greptile SummaryThis PR adds client-side Mermaid diagram rendering to the docs site by introducing a new
Confidence Score: 5/5Safe to merge for a static docs site where diagram content is fully author-controlled All changed code paths are straightforward: the mermaid library is lazily imported only when diagrams are actually present, the src/components/MermaidRenderer.astro — the Important Files Changed
Sequence DiagramsequenceDiagram
participant Browser
participant AstroRuntime as Astro Runtime
participant MermaidRenderer as MermaidRenderer.astro (script)
participant MermaidLib as mermaid (dynamic import)
participant DOM
AstroRuntime->>Browser: Page HTML delivered
Browser->>MermaidRenderer: Script executes (inline)
MermaidRenderer->>DOM: "querySelectorAll pre[data-language="mermaid"]"
alt No diagrams found
MermaidRenderer-->>Browser: return (no import)
else Diagrams present
MermaidRenderer->>MermaidLib: await import('mermaid')
MermaidLib-->>MermaidRenderer: mermaid instance
MermaidRenderer->>MermaidLib: "mermaid.initialize({ securityLevel: 'loose' })"
loop For each diagram
MermaidRenderer->>MermaidLib: mermaid.render(id, source)
MermaidLib-->>MermaidRenderer: "{ svg }"
MermaidRenderer->>DOM: "container.innerHTML = svg"
MermaidRenderer->>DOM: wrapper.replaceWith(container)
end
end
AstroRuntime->>MermaidRenderer: astro:page-load (on navigation)
MermaidRenderer->>DOM: querySelectorAll (skips data-mermaid-rendered nodes)
Reviews (2): Last reviewed commit: "fix: lazy load mermaid diagrams" | Re-trigger Greptile |
|
@greptileai it's review time |
See
/docs/integrations/sdk/integration/messaging