Repository navigation
Count only a closed block as frontmatter, so AddFrontmatter writes a header above an opening rule [patch] - #186
Merged
Conversation
…header above an opening rule [patch] HasFrontmatter returned true as soon as the first line was a delimiter, while the block splitter needs a closing one. A document opening with a thematic break that never closes made AddFrontmatter take the "present but unreadable" branch and return the input unchanged, silently dropping the new properties. HasFrontmatter now asks the splitter, and the first-line check moves to a private OpensWithDelimiter helper that keeps the BOM and trailing-whitespace rules. Fixes #157 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QiAEodt8KsqJyMYzdfoAfo
|
This was referenced Oct 6, 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 #157
Problem
HasFrontmatterreturnedtruewhenever the first line was a delimiter, butTrySplitFrontmatterBlocksalso needs a closing delimiter. When a document opens with a thematic break that never closes ("---\n\n# Heading\n\nText\n"), the two disagree.AddFrontmatterthen took the "present but unreadable, leave it alone" branch and returned the input unchanged, so the new properties were silently lost.Change
HasFrontmatternow returnsTrySplitFrontmatterBlocks(...), so only a closed block counts.OpensWithDelimiterhelper. The splitter uses that helper as its precondition.ExtractFrontmatterObjectsno longer reports a never-closed opening rule as an unreadable block. A document like that has no frontmatter, soAddFrontmatterprepends a header to it the same way it does for any other document without one.RemoveFrontmatternow returns such a document unchanged, like any document without frontmatter. Before, it was trimmed and given a trailing newline.Tests
New
UnclosedOpeningRuleTests, coveringHasFrontmatter,ExtractFrontmatter,AddFrontmatter(header goes in front, the original---rule stays in the body, and the result round-trips) andRemoveFrontmatter.Checked locally:
HasFrontmatterandAddFrontmattertests fail with theFrontmatter.cschange reverted.🤖 Generated with Claude Code
https://claude.ai/code/session_01QiAEodt8KsqJyMYzdfoAfo
Generated by Claude Code