Keep the first body line's indentation when rewriting a document [patch] - #172
Merged
Merged
Conversation
AddFrontmatter, ReplaceFrontmatter, RemoveFrontmatter and ExtractBody trimmed the body with string.Trim(), which also stripped the leading indentation of the first content line and turned a leading indented code block into a prose paragraph. They now drop only the leading blank lines and trailing whitespace, matching how CombineFrontmatter keeps the body. Fixes #146 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AFCuHRLN6NWMQ4DJNZApHa
|
This was referenced Sep 30, 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 #146
What changed
AddFrontmatter,ReplaceFrontmatter,RemoveFrontmatterandExtractBodytrimmed the body withstring.Trim(). That also removed the indentation of the first content line, so a body that opened with an indented code block rendered as a prose paragraph.A new private
TrimBodyhelper replaces those fourTrim()calls. It drops only the whitespace-only lines before the first content line, plus trailing whitespace, and leaves that line's indentation alone. That matches whatCombineFrontmatteralready does with the body.Tests
Frontmatter.Test/BodyIndentationTests.csruns all four methods on a body that starts with an indented code block. It also covers a tab-indented first line after blank lines and a body that is only whitespace.dotnet test)Frontmatter.cschange reverted: 6 of the new tests fail🤖 Generated with Claude Code
https://claude.ai/code/session_01AFCuHRLN6NWMQ4DJNZApHa
Generated by Claude Code