Skip to content

feat(Markdown): add Mermaid fence renderer - #6669

Closed
ernestt wants to merge 1 commit into
markdown-upgrade/13-katexfrom
markdown-upgrade/14-mermaid
Closed

ernestt wants to merge 1 commit into
markdown-upgrade/13-katexfrom
markdown-upgrade/14-mermaid

Conversation

@ernestt

@ernestt ernestt commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

User need

Exact mermaid fences can render strict diagrams while preserving an ordinary CodeBlock during loading or failure.

Problem and solution fit

Diagram hosts otherwise duplicate fence recognition, async loading, global Mermaid serialization, SVG sanitization, and fallback behavior. The plugin packages those constraints behind the canonical semantic-fence protocol.

Current specification

AST-039 and the Markdown semantic-fence/plugin contracts. Pinned source.

Public delta and caller burden

Export a tree-shakeable Mermaid plugin, load Mermaid's browser bundle only after mount, keep optional renderer adapters out of the docsite's eager playground scope, serialize global engine access, enforce strict configuration, parse SVG without executing authored HTML, remove active/unsafe content, and retain source fallback.

Design and alternatives

The capability is explicit and opt-in where it changes syntax, rendering, or package weight. Existing defaults and replacement seams remain compatible; broader alternatives stay outside this PR.

Evidence

Real-browser evidence

Mermaid renderer before and after

Focused behavior and compatibility coverage ships with the implementation.

Scope

  • One capability is added.
  • Unrelated fixes and policy changes were split into adjacent stack entries.
  • Consumer docs and focused tests ship with the feature.
  • Public text and artifacts contain no internal context.

Testing

  • Focused: Mermaid unit/integration, sanitizer, serialization, fallback, diagnostics, public export, playground-scope regression, typecheck, production consumer build, and Storybook tests.
  • Stack head: pnpm exec vitest run packages/core/src/Markdown packages/core/src/CodeBlock — 37 files, 760 tests.
  • Stack head: pnpm --filter @astryxdesign/core typecheck.
  • Repository checks: pnpm check:repo.

Stack

Previous: #6668 · Next: #6670 · Each PR is intentionally one commit and one primary intent.

@vercel

vercel Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Sep 26, 2026 3:44pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
📝 Draft — not reviewed automatically (for maintainers only) Sep 28, 2026, 7:44 PM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 26, 2026
@ernestt
ernestt force-pushed the markdown-upgrade/14-mermaid branch from bf319f8 to 024f452 Compare September 26, 2026 15:10
@ernestt
ernestt force-pushed the markdown-upgrade/14-mermaid branch from 024f452 to edef89c Compare September 26, 2026 15:25
Summary:
Add an optional, lazy Mermaid semantic-fence plugin with serialized strict rendering, sanitized SVG output, source-free diagnostics, and an ordinary CodeBlock fallback. Expose the tree-shakeable subpath and document its accessibility, security, and theming contracts.

Test Plan:
- pnpm exec vitest run packages/core/src/Markdown --root .
- pnpm --filter @astryxdesign/core typecheck
- pnpm --filter @astryxdesign/core typecheck:docs
- pnpm --filter @astryxdesign/core build
- pnpm check:repo
- pnpm visual:probe-theme:check
@ernestt

ernestt commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

@cixzhang — I’d appreciate your feedback on this draft.

Focus: Exact mermaid fences can render strict diagrams while preserving an ordinary CodeBlock during loading or failure.

This is PR 14/20 in the linked Markdown stack. It is intentionally one commit and one primary intent; the description includes matched before/after screenshots and previous/next links, so you can review just this PR’s delta.

@humbertovirtudes humbertovirtudes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The lazy fallback, global render serialisation, diagnostics, and basic active-content tests are good, but two blockers remain. The Mermaid contract needs to land as current authority before this implementation. More importantly, the SVG importer is a partial deny-list: it removes several active elements, event attributes, and unsafe hrefs, but still admits CSS and other resource-bearing SVG surfaces before mounting the tree. Please replace this with a fail-closed SVG element and attribute policy and cover style and resource URL sinks.

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Sep 27, 2026
@ernestt
ernestt added this pull request to stack #6700 September 28, 2026 18:03
github-actions Bot added a commit that referenced this pull request Sep 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR Analysis Report

Preview availability: Storybook and Sandbox are not both ready on the exact-head Vercel preview. CI concluded failure.

Modified Components

Outline (@astryxdesign/core)
Metric Before After Delta
Bundle Size (ESM) N/A N/A N/A
Lines of Code N/A 719 -
Complexity N/A High (28) -

Bundle Size Summary

Package Size (ESM) Size (CJS) Gzipped
@astryxdesign/core N/A 4.9KB 1.2KB

Accessibility Audit

Status: No accessibility violations detected.

Visual Regression

2 of 422 shot(s) changed. View the report

A change here is a question, not a failure: check whether the after is the
picture you intended. Record that review on the PR. Baseline maintenance is an
explicit dispatch of CI; this report never rewrites the baseline or adds a release gate.

component story theme mode pixels
Markdown Default probe dark 29,661
Markdown Default probe light 29,652
Markdown — Default — probe dark
BeforeAfterDiff
Before visual regression frame After visual regression frame Pixel difference frame
Markdown — Default — probe light
BeforeAfterDiff
Before visual regression frame After visual regression frame Pixel difference frame

Generated by PR Enrichment workflow | View full report

@ernestt ernestt closed this Oct 9, 2026
@github-actions
github-actions Bot deleted the markdown-upgrade/14-mermaid branch October 10, 2026 06:22

This branch was successfully deployed

1 active deployment
Preview — 5bcdc243 Deployed Sep 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:spec-owner-review Current knowledge records await owner approval

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants