Keep every frontmatter block when adding or combining properties [patch] - #166
Merged
Merged
Conversation
AddFrontmatter merged the new properties into the first block only, then rebuilt the document from the body after all blocks, so properties in later blocks were deleted. It now folds every block in first. CombineFrontmatter skipped a block it could not parse but still started the body after it, so an unreadable first block was deleted whenever a later block parsed. It now returns the input unchanged in that case, matching AddFrontmatter's guard. Fixes #138 Fixes #139 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RpyD4tJtfe5diTxv8UEw2x
|
This was referenced Sep 29, 2026
This was referenced Sep 29, 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 #138
Fixes #139
Both issues had the same cause: the header was rebuilt from only some of the blocks, but the body still started after all of them. Per the triage on #138, they are fixed together here.
Changes
AddFrontmatternow folds every parsed block together (first block wins a repeated key) before it merges in the new properties. It used to merge into the first block only, which deletedtagsin the issue's repro.ExtractFrontmatterObjectsnow reports when a non-blank block fails to parse.CombineFrontmatterreturns (and caches) its input unchanged in that case, andAddFrontmatteruses the same flag in place of its old guard.Note on the #139 repro
The repro in the issue (an unparseable second block) no longer loses data on
main.TrySplitFrontmatterBlocksonly accepts a follow-on block that parses, so that block already stays verbatim in the body. The data loss still happens when the first block is unparseable and a later one parses: the first block is always taken as frontmatter, and it was being dropped. The tests cover that case, and a guard test keeps the second-block case in the body.Tests
StackedBlockPreservationTests. WithFrontmatter.csreverted, 5 of its tests fail. With the fix, the full suite passes (204/204).🤖 Generated with Claude Code
https://claude.ai/code/session_01RpyD4tJtfe5diTxv8UEw2x
Generated by Claude Code