Skip to content

Add Mermaid MDX component and docs for diagram rendering#1

Open
Clickin wants to merge 1 commit intomainfrom
codex/add-diagram-rendering-to-blog-pipeline
Open

Add Mermaid MDX component and docs for diagram rendering#1
Clickin wants to merge 1 commit intomainfrom
codex/add-diagram-rendering-to-blog-pipeline

Conversation

@Clickin
Copy link
Owner

@Clickin Clickin commented Mar 9, 2026

Motivation

  • Provide a way to manage diagrams as code in MDX posts using Mermaid instead of shipping image files.
  • Ensure diagrams respect the site's light/dark theme and re-render when the theme changes.
  • Document how to use the Mermaid MDX component for authors.

Description

  • Add a new client-side component src/components/Mermaid.astro that imports mermaid, renders .mermaid blocks, initializes with the current theme, and watches document.documentElement.class to reset and re-render charts on theme changes.
  • Add the mermaid dependency to package.json to enable bundling and runtime use in the browser.
  • Update README.md with a usage example showing how to import and use the Mermaid component in an MDX post and note that mermaid is managed as an npm dependency.

Testing

  • No automated tests were executed for this change.

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant