Skip to content

Keep the first body line's indentation when rewriting a document [patch] - #172

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/146-keep-body-indentation
Sep 30, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/146-keep-body-indentation

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #146

What changed

AddFrontmatter, ReplaceFrontmatter, RemoveFrontmatter and ExtractBody trimmed the body with string.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 TrimBody helper replaces those four Trim() 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 what CombineFrontmatter already does with the body.

Tests

Frontmatter.Test/BodyIndentationTests.cs runs 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.

  • With the fix: 220/220 pass (dotnet test)
  • With the Frontmatter.cs change reverted: 6 of the new tests fail

🤖 Generated with Claude Code

https://claude.ai/code/session_01AFCuHRLN6NWMQ4DJNZApHa


Generated by Claude Code

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
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 775e991 into main Sep 30, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/146-keep-body-indentation branch September 30, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants