Recognise frontmatter delimiters only as whole lines at the top of a document - #135
Merged
Merged
Conversation
…document The document was split on every "---" followed by a newline, anywhere in the text. This caused four problems: - A markdown horizontal rule pair around a "key: value" paragraph was merged into the header. - A value such as "foo---" split the header mid-line. - CombineFrontmatter merged the second block into the header and also left it in the body. - A closing "---" at the very end of the file was not recognised, so AddFrontmatter then overwrote the properties it could not see. Frontmatter is now parsed line by line. The first line opens a block, and the block closes at the next line that is exactly "---" (trailing whitespace allowed), including one at the end of the input. Further blocks are taken only while they follow directly. Every CRLF, LF and CR ending is recognised, so mixed-ending documents still parse. AddFrontmatter no longer treats frontmatter it cannot read as empty. It returns the document unchanged, so a parsing gap can't lose properties. Fixes #132 Fixes #133 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VpbpayL5Kw99JfbzgkJfKa
|
This was referenced Sep 26, 2026
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.



Fixes #132
Fixes #133
The triage on #133 asked for both fixes in one PR, because they share a root cause.
What was wrong
ExtractFrontmatterObjectssplit the whole document on every---followed by a newline:key: valueparagraph between two rules was merged into the header. A value likefoo---split the header mid-line.CombineFrontmattermerged the second block into the header and also left it in the body.---at the very end of the file wasn't recognised, soExtractFrontmatterreturnednull.AddFrontmatterthen treated the existing properties as empty and overwrote them.Change
TrySplitFrontmatterBlocks:---; trailing whitespace is allowed.AddFrontmatterguard, as the triage asked: when frontmatter is present but can't be read, the document comes back unchanged instead of being overwritten. An empty block (---\n---) still gets the new properties.---is now treated as no frontmatter. Before, everything after it was parsed as a block.Tests
New
DelimiterLineTests, 8 cases, covering each acceptance item:note: histay in the body, for bothExtractBodyandCombineFrontmatter(exact output).foo---value mid-line.author: B.ExtractFrontmatterandAddFrontmatter(keepstitleandauthor).Against the original
Frontmatter.cs, 6 of the 8 new tests fail. The other two cover behaviour that already worked and must not regress. With the fix, all 153 tests pass.🤖 Generated with Claude Code
https://claude.ai/code/session_01VpbpayL5Kw99JfbzgkJfKa
Generated by Claude Code