Skip to content

fix(better-files): show front matter as a YAML code block in the preview - #41

Open
nocstah wants to merge 1 commit into
munza:mainfrom
nocstah:better-files-front-matter
Open

nocstah wants to merge 1 commit into
munza:mainfrom
nocstah:better-files-front-matter

Conversation

@nocstah

@nocstah nocstah commented Nov 19, 2026

Copy link
Copy Markdown

The problem

A Markdown file that starts with front matter (Jekyll pages, SKILL.md files, DESIGN.md design systems) shows in Better Files' preview as a horizontal rule followed by every YAML line run together as one long heading. TextView reads the opening --- as a rule and the closing --- as a setext underline for the paragraph above it.

The fix

markdownBlocks takes the front matter off first and puts it at the top as a yaml code block, the way GitHub shows front matter apart from the text. It is drawn like any other code block: coloured, with a copy button.

It counts as front matter only when:

  • --- is the first line (after a byte-order mark too);
  • it is closed by --- or ...;
  • it is empty or opens with a key: or a # comment.

A file that only starts with a rule and some prose is left as it was. A lone --- still renders as a rule, as the existing test checks.

Independent of #39 and #40: this branch is cut from main. I left mod.json's version alone, since those two are open as well.

Testing

  • node --test better-files/tests/*.test.cjs: 111 pass. The new cases cover front matter followed by a heading, a BOM with CRLF closed by ..., empty front matter, and four inputs that must stay text (prose between rules, --- not on the first line, unclosed, indented).
  • node --test site/tests/*.test.cjs passes, and herdr-app check passes.
  • A 305-line DESIGN.md with 165 lines of tokens in its front matter now opens with one yaml block (165 lines), followed by its title, instead of a single 170-line heading.

🤖 Generated with Claude Code

A Markdown file that starts with front matter (`---` … `---`, as in
Jekyll pages, skills and DESIGN.md files) showed in the preview as a
horizontal rule followed by every YAML line run together as one
heading: TextView reads the opening `---` as a rule and the closing one
as a setext underline. The front matter now comes first as a `yaml`
code block, the way GitHub shows it apart from the text.

It counts as front matter when `---` is the first line (after a
byte-order mark too), it is closed by `---` or `...`, and it is empty or
opens with a `key:` or a `#` comment. A file that only starts with a
rule and some prose is left as it was.

Tests: front matter with a heading after it, a BOM with CRLF closed by
`...`, empty front matter, and four cases that stay text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant