Repository navigation
Keep the header as written when AddFrontmatter adds no new key [patch] - #215
Merged
Merged
Conversation
TryInsertIntoHeader bailed out when every key passed in was already in the header, so AddFrontmatter fell back to rebuilding it and dropped its comments and quoting. With nothing to insert, the header text is now kept as written and only the body is rejoined, as the insert path does. Fixes #213 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW39LG7U7W2n8oFVbZp
|
This was referenced Nov 16, 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 #213
What changed
TryInsertIntoHeaderreturnedfalsewhen every key passed toAddFrontmatterwas already in the header.AddFrontmatterthen fell back toReplaceFrontmatter, which rebuilds the header and drops its comments and quoting (title: ~→title:,'title': a→title: a).The early exit on
added.Count == 0is gone. With nothing to insert, the header lines are kept as written and joined to the body throughJoinHeaderAndBody, the same way the insert path writes the body (#210/#211). The existing read-back check still applies, so anything that does not round-trip (a flow-mapping header, for example) still falls back to the rebuild. Stacked blocks still take the fold-and-rebuild path.Tests
AddKeepsHeaderTextTests.AddFrontmatter_EveryKeyAlreadyPresent_KeepsTheHeaderAsWrittencovers comments, a~null, a quoted key, and CRLF with a...end marker.AddFrontmatter_EveryKeyAlreadyPresent_WritesTheBodyAsARebuiltHeaderWritesItpins the body normalization.dotnet teston Linux).Generated by Claude Code