Recognise an opening delimiter with trailing whitespace or a leading BOM - #143
Merged
Merged
Conversation
…leading BOM HasFrontmatter required the document to start with exactly "---" and a newline, while closing delimiters already allowed trailing whitespace. A header opened by "--- " or "---\t", or preceded by a byte order mark, was therefore invisible, and AddFrontmatter stacked a second header above it. The opening line now goes through IsDelimiterLine like every other delimiter, after skipping a leading BOM, both in HasFrontmatter and in the block splitter. Fixes #141 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KMqfUfzWj2Gmdz1EqYdnLe
|
This was referenced Sep 27, 2026
This was referenced Sep 28, 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 #141
What was wrong
HasFrontmatteronly matched a document that started with exactly---followed by a newline. Closing delimiters already went throughIsDelimiterLine, which allows trailing whitespace. So a header opened by---or---\t(often left behind by editors), or preceded by a BOM, was not recognised.ExtractFrontmatterreturnednull, andAddFrontmatterstacked a second header on top of the real one.Change
HasFrontmatterskips a leading BOM (``) and checks the first line withIsDelimiterLine, so opening and closing delimiters follow the same rule. It still requires a line ending after the opening delimiter.TrySplitFrontmatterBlocksskips the same BOM when it tests the opening line.DetectNewLineand thektsu.Extensionsusing are removed, because nothing uses them now.Tests
DelimiterLineTestscovers---,---\tand a BOM prefix acrossHasFrontmatter,ExtractFrontmatter/ExtractBodyandAddFrontmatter.AddFrontmatternow merges into the existing header and no longer stacks a second one. There is also a test that a bare delimiter with no line ending is still not frontmatter.🤖 Generated with Claude Code
https://claude.ai/code/session_01KMqfUfzWj2Gmdz1EqYdnLe
Generated by Claude Code