Repository navigation
feat(preview): render Mermaid diagrams on demand - #31
Merged
Merged
Conversation
- Detect Mermaid fences from GitHub's <pre lang="mermaid">, class="mermaid" wrappers, and Markdown fence info. - Add a Reader setting (off by default) that lazy-loads a self-hosted Mermaid 11.17.2 bundle when a diagram approaches the viewport. - Render with strict security mode, theme variables from the active CSS theme, a Source toggle, Copy, and a source fallback on failure. - Re-render diagrams when the theme changes; bump app.js to v114 and the PWA shell cache to v148. Co-Authored-By: Claude Code <noreply@anthropic.com>
|
🔎 Cloudflare preview: https://c57026f2-feedreader.phatpham9.workers.dev Uploaded from |
- Strip %%{...}%% directives and YAML config frontmatter from untrusted
diagram source so it cannot downgrade securityLevel or enable HTML
labels.
- Sanitize the generated SVG and its foreignObject labels with vendored
DOMPurify 3.5.0 before importing any node into the DOM; fail closed to
the Source view if the sanitizer cannot load.
- Bump app.js to v115 and the PWA shell cache to v149.
Co-Authored-By: Claude Code <noreply@anthropic.com>
- Move the Mermaid option into the Article preview section and show it only while preview is enabled. - Bump app.js to v116 and the PWA shell cache to v150. Co-Authored-By: Claude Code <noreply@anthropic.com>
- Show the Mermaid option whenever Article preview is shown; disable its checkbox while preview is off instead of hiding the option. - Align the option with the preview option and dim the disabled state. - Bump app.js to v117 and the PWA shell cache to v151. Co-Authored-By: Claude Code <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mermaid fences in previews now render as diagrams when the reader opts in. The setting is off by default, and the renderer is fetched only when a diagram is present.
securityLevelor re-enable HTML labels:%%{...}%%directives and YAML config frontmatter are stripped before rendering.foreignObjectlabels, before any node is imported. If the sanitizer cannot load, the viewer falls back to Source instead of rendering.feedreader.mermaidEnabled; Source toggles the fence and Copy copies it.Evidence
After: Local and deployed previews of
vercel-labs/openreviewand the Polymarket HN article rendered their diagrams — 10foreignObjectlabels preserved, theme switching re-rendered with the active colors, Source toggled to the fence, Copy returnedCopied.%%{init: {"securityLevel":"loose"}}%%, YAMLconfig: securityLevel: loose,iframe/img onerrorlabels, andclick ... "javascript:..."produced no handler execution, no<script>/<iframe>, and nojavascript:URLs after sanitization.npm test— 30 files, 239 tests passed.npm run typecheck— clean. New assertions cover<pre lang="mermaid">,class="mermaid"wrappers, plainlang="en"(not treated as code), and Markdown Mermaid fences.Merge Danger
Door: two-way — reverting removes the feature and the vendored assets.
Blast Radius: preview rendering and static assets
The assets add about 3.4 MB (roughly 960 KB gzip) to
web-static; they are lazily fetched and cached by the service worker after first use. Previews cached before deploy lack themermaidlanguage hint until they refresh (30-minute TTL). The setting is off by default, so existing users see no change until they opt in.🤖 Generated with Claude Code