Add Mermaid MDX component and docs for diagram rendering#1
Add Mermaid MDX component and docs for diagram rendering#1
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c7ed68ee21
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const source = node.dataset.mermaidSource; | ||
| if (!source) return; | ||
| node.removeAttribute("data-processed"); | ||
| node.innerHTML = source; |
There was a problem hiding this comment.
Use textContent when resetting Mermaid source
Resetting the chart with node.innerHTML = source re-parses Mermaid text as HTML during theme changes, which corrupts valid diagram syntax containing <... sequences (for example B-->|x<y|C gets truncated by the HTML parser) and can cause re-rendered diagrams to break or render incorrectly after toggling dark/light mode. This restore path should write plain text (textContent) so the original Mermaid source is preserved exactly.
Useful? React with 👍 / 👎.
Motivation
MermaidMDX component for authors.Description
src/components/Mermaid.astrothat importsmermaid, renders.mermaidblocks, initializes with the current theme, and watchesdocument.documentElement.classto reset and re-render charts on theme changes.mermaiddependency topackage.jsonto enable bundling and runtime use in the browser.README.mdwith a usage example showing how to import and use theMermaidcomponent in an MDX post and note thatmermaidis managed as an npm dependency.Testing
Codex Task