Skip to content

feat(client): render YAML frontmatter in markdown preview (full/diff)#442

Draft
woo-cie wants to merge 6 commits into
yoshiko-pg:mainfrom
woo-cie:feat/frontmatter-preview
Draft

feat(client): render YAML frontmatter in markdown preview (full/diff)#442
woo-cie wants to merge 6 commits into
yoshiko-pg:mainfrom
woo-cie:feat/frontmatter-preview

Conversation

@woo-cie

@woo-cie woo-cie commented Jul 12, 2026

Copy link
Copy Markdown

Closes #441

Summary

Render YAML frontmatter as a structured key/value table in both full-preview (snapshot) and diff-preview (key-level diff) tabs of the markdown preview.

Plan (attack in progress)

Parser: remark-frontmatter (official unified plugin) + js-yaml direct call, encapsulated behind extractFrontmatter(text) pure helper.

  • Rationale: keeps the existing unified/remark ecosystem consistent while avoiding the EOL risk of the individually-maintained remark-parse-frontmatter.
  • js-yaml v4 uses safe load() default (no !!js/function).
  • Reversible: swapping the helper internals is enough to migrate to a different parser.

Rendering:

  • New FrontmatterTable with mode: 'snapshot' | 'diff' and label? props.
  • Diff mode reuses existing diff Tailwind classes (bg-diff-addition-bg etc.).
  • Modifications rendered as two rows (before/after) — GitHub line-diff style.

Diff computation:

  • computeFrontmatterDiff(old, new) pure function.
  • Canonical JSON.stringify (recursive key sort) to avoid false positives from key-order changes.

Two-side fetch (diff-preview only, case α):

  • Parallel Promise.allSettled on the existing /api/blob/${path}?ref=${ref} API.
  • Per-file.status: added / deleted / renamed / modified handled explicitly.
  • stdin: snapshot fallback with explicit label.
  • Skip fetch when the leading chunk clearly has no --- (perf).

full-preview: unchanged (snapshot only). Preserves the "read vs. diff" semantic separation.

Tasks (10)

  1. Sample markdowns under docs/syntax-sample/ (4 nesting patterns + before/after diff pair)
  2. remark-frontmatter + js-yaml deps + extractFrontmatter helper
  3. FrontmatterTable snapshot mode
  4. Full-preview integration
  5. Two-side fetch refactor (MarkdownDiffViewer)
  6. computeFrontmatterDiff pure function (canonical stringify)
  7. FrontmatterTable diff mode
  8. Diff-preview integration
  9. verifier: build/typecheck/tests, pnpm why js-yaml, bundle size, 20 visual patterns
  10. reviewer: 6-axis review

Test plan

  • Existing markdown files without frontmatter render identically (no regression)
  • full-preview renders the frontmatter table before the body when present
  • diff-preview renders diff-highlighted table with additions / deletions / modifications for the 4 file.status variants
  • stdin mode falls back to snapshot with a clear label
  • computeFrontmatterDiff unit tests: key-order-change (no false positive), type change, nested, array, null
  • pnpm build, pnpm typecheck, existing tests pass
  • Bundle-size increase measured and recorded
  • pnpm why js-yaml resolves to a single v4.x version

woo-cie and others added 6 commits July 12, 2026 19:52
Add before/after markdown pairs covering scalar, array, single-level
nested, and deep-nested YAML frontmatter changes for the frontmatter
preview feature.
…#441)

Add remark-frontmatter and js-yaml dependencies for the upcoming
frontmatter preview feature, plus a standalone extractFrontmatter
helper that regex-splits a leading YAML block and safely parses it.
remark-frontmatter is unused for now (wired into the unified pipeline
in a later task); ignored in knip.json until then.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…pg#441)

Restructures MarkdownDiffViewer's preview fetch logic to retrieve both
base and target blobs in parallel via Promise.allSettled, laying the
groundwork for diff-preview frontmatter rendering while keeping
MarkdownFullPreview and MarkdownDiffPreview behavior unchanged.
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.

feat(client): render YAML frontmatter in markdown preview (full/diff)

1 participant