Skip to content

Hide YAML frontmatter in markdown preview - #139

Merged
mattenarle10 merged 3 commits into
mattenarle10:mainfrom
OliverBennettdev:agent/hide-yaml-frontmatter
Aug 17, 2026
Merged

Hide YAML frontmatter in markdown preview#139
mattenarle10 merged 3 commits into
mattenarle10:mainfrom
OliverBennettdev:agent/hide-yaml-frontmatter

Conversation

@OliverBennettdev

Copy link
Copy Markdown
Contributor

Summary

  • hide YAML frontmatter when it appears at the very start of a Markdown file
  • preserve original source positions by masking frontmatter characters instead of deleting lines
  • keep thematic breaks elsewhere in the document unchanged
  • leave unterminated opening delimiters as ordinary Markdown
  • add regression coverage for preview output and source-line mapping

Root cause

src/lib/markdown.ts passed the source directly to markdown-it. Without a frontmatter rule, the opening --- was rendered as a thematic break and the closing --- could turn the metadata above it into a setext heading.

Implementation

This uses a small dependency-free maskYamlFrontmatter helper. It replaces only non-newline characters in a leading, closed --- block with spaces before markdown parsing. That hides the metadata while preserving both line and character positions, so the existing data-sline / data-eline mapping remains aligned with the original source.

The masked source is also used for fenced-language discovery, so metadata cannot trigger unnecessary syntax-highlighter loading.

Validation

  • helper compiles with TypeScript
  • local behavior checks cover LF, CRLF, mid-document thematic breaks, unterminated frontmatter, and a closing delimiter at EOF
  • regression tests added in tests/markdown.test.ts
  • GitHub Actions will validate repository typechecking and Rust checks on this PR

Closes #134

@OliverBennettdev
OliverBennettdev marked this pull request as ready for review August 16, 2026 03:37

Copy link
Copy Markdown
Owner

The implementation matches #134 and the regression coverage looks focused, including source-line preservation, CRLF handling, mid-document thematic breaks, and unterminated frontmatter. I do not see any GitHub CI checks reported for this branch yet, so please enable/run the repository checks before merge. Once CI is green, this can close #134.

@mattenarle10
mattenarle10 merged commit 042ecac into mattenarle10:main Aug 17, 2026

Copy link
Copy Markdown
Owner

Thanks for the focused fix and regression tests. The frontmatter masking preserves source-line mapping and keeps regular thematic breaks working, which is exactly what the preview needed. Merged, and #134 is now closed.

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] Skip YAML frontmatter in preview instead of rendering it as an <h2>

2 participants