Skip to content

Write a rewritten document's header in the document's own line endings [patch] - #187

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/158-match-input-newlines
Oct 6, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/158-match-input-newlines

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #158

Problem

The parser accepts CRLF, LF and CR. But CombineFrontmatter, AddFrontmatter, ReplaceFrontmatter and RemoveFrontmatter built the delimiters, the YAML line breaks and the trailing newline from Environment.NewLine, while copying the body through verbatim. On Linux, a CRLF document came back with an LF header and a mixed body. On Windows the same thing happened in reverse to LF documents.

Change

  • New private NewLineOf(input) returns the document's first line ending (CRLF, LF or CR). It falls back to Environment.NewLine when the document has no line breaks at all.
  • New private WithNewLines(text, newLine) rewrites the serialized YAML's line breaks to match. It reuses SplitLines, which keeps it netstandard2.0-friendly.
  • All four writers use these instead of Environment.NewLine. The body is still copied as-is.

Behaviour stays the same for documents that already use the host's line ending, and for documents with no line breaks.

Tests

New LineEndingTests covers CRLF and LF input for CombineFrontmatter, AddFrontmatter (with and without an existing header), ReplaceFrontmatter (including a multi-line YAML list) and RemoveFrontmatter. Each test asserts that the output contains only the input's line ending.

Checked locally on Linux:

  • The five CRLF cases fail with the Frontmatter.cs change reverted. The LF cases pass either way, because LF is the host's line ending here. On Windows they would be the failing ones.
  • The full suite passes with the change (247/247).

Note on overlap

This PR and #185/#186 change separate regions of Frontmatter.cs, so they should merge cleanly in any order.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QiAEodt8KsqJyMYzdfoAfo


Generated by Claude Code

…s [patch]

CombineFrontmatter, AddFrontmatter, ReplaceFrontmatter and RemoveFrontmatter
built the delimiters, the YAML lines and the trailing newline from
Environment.NewLine while copying the body verbatim, so a CRLF document on
Linux (or an LF one on Windows) came back with mixed line endings. Each writer
now uses the input's first line ending, falling back to Environment.NewLine
when it has none, and rewrites the serialized YAML to match.

Fixes #158

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QiAEodt8KsqJyMYzdfoAfo
@sonarqubecloud

sonarqubecloud Bot commented Oct 6, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rewriting a CRLF document (or an LF one on Windows) produces mixed line endings: header uses Environment.NewLine, body keeps the original

2 participants