fix(preview): harden markdown preview#860
Merged
Merged
Conversation
Stabilize headline anchor generation and local markdown error handling. Catch invalid Mermaid diagrams without unhandled page errors and add regression coverage for preview navigation, unicode anchors, and markdown-it sample content.
Contributor
There was a problem hiding this comment.
Pull request overview
Stabilizes Markdown preview rendering by moving heading anchor generation into the rehype pipeline, adding local error handling for Mermaid render failures, and introducing regression coverage for navigation and sample Markdown content.
Changes:
- Generate deterministic, unicode-friendly heading
ids during rehype processing and update heading anchor rendering/CSS accordingly (removes the zustand headlines store). - Catch Mermaid parse/render failures and render a local fallback UI instead of letting the preview crash.
- Add Markdown preview error boundary and expand regression coverage (hash navigation, unicode anchors, markdown-it sample, invalid Mermaid).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| ui/leafwiki-ui/src/index.css | Update selectors for new headline anchor DOM/classes. |
| ui/leafwiki-ui/src/features/preview/useMermaidInjector.ts | Wrap Mermaid render in try/catch and surface errors via callback. |
| ui/leafwiki-ui/src/features/preview/rehypeLineNumber.ts | Add stable slug/id generation for headings + keep data-line. |
| ui/leafwiki-ui/src/features/preview/MermaidBlock.tsx | Display local fallback UI when Mermaid rendering fails. |
| ui/leafwiki-ui/src/features/preview/MarkdownPreview.tsx | Add error boundary; adjust sanitize schema for new attrs and anchor behavior. |
| ui/leafwiki-ui/src/features/preview/headlines.ts | Remove prior zustand-based slug tracking implementation. |
| ui/leafwiki-ui/src/features/preview/Headline.tsx | Render anchors without nesting links; support generated-id signaling. |
| internal/core/markdown/frontmatter.go | Tighten YAML frontmatter detection to avoid false positives. |
| internal/core/markdown/frontmatter_test.go | Add regression tests for non-frontmatter separator blocks/link definitions. |
| e2e/tests/page.spec.ts | Add e2e coverage for heading anchors, navigation responsiveness, invalid Mermaid. |
| e2e/assets/markdown-it-sample.md | Add sample content fixture used by e2e navigation/regression tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Restore sanitize clobber protection with a leafwiki id prefix and align anchor expectations. Add an accessible label for icon-only headline anchors and remove the unsafe Mermaid dataLine cast.
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.
Stabilize headline anchor generation and local markdown error handling.
Catch invalid Mermaid diagrams without unhandled page errors and add regression coverage for preview navigation, unicode anchors, and markdown-it sample content.