Skip to content

fix(preview): harden markdown preview#860

Merged
perber merged 2 commits into
mainfrom
fix/preview-resilience
Apr 10, 2026
Merged

fix(preview): harden markdown preview#860
perber merged 2 commits into
mainfrom
fix/preview-resilience

Conversation

@perber
Copy link
Copy Markdown
Owner

@perber perber commented Apr 9, 2026

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.

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.
Copilot AI review requested due to automatic review settings April 9, 2026 15:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread ui/leafwiki-ui/src/features/preview/MarkdownPreview.tsx Outdated
Comment thread ui/leafwiki-ui/src/features/preview/Headline.tsx
Comment thread ui/leafwiki-ui/src/features/preview/MermaidBlock.tsx Outdated
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.
@perber perber merged commit 33fd69b into main Apr 10, 2026
5 checks passed
@perber perber deleted the fix/preview-resilience branch April 10, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants