Repository navigation
Write a rewritten document's header in the document's own line endings [patch] - #187
Merged
Merged
Conversation
…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
|
This was referenced Oct 6, 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 #158
Problem
The parser accepts CRLF, LF and CR. But
CombineFrontmatter,AddFrontmatter,ReplaceFrontmatterandRemoveFrontmatterbuilt the delimiters, the YAML line breaks and the trailing newline fromEnvironment.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
NewLineOf(input)returns the document's first line ending (CRLF, LF or CR). It falls back toEnvironment.NewLinewhen the document has no line breaks at all.WithNewLines(text, newLine)rewrites the serialized YAML's line breaks to match. It reusesSplitLines, which keeps it netstandard2.0-friendly.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
LineEndingTestscovers CRLF and LF input forCombineFrontmatter,AddFrontmatter(with and without an existing header),ReplaceFrontmatter(including a multi-line YAML list) andRemoveFrontmatter. Each test asserts that the output contains only the input's line ending.Checked locally on Linux:
Frontmatter.cschange reverted. The LF cases pass either way, because LF is the host's line ending here. On Windows they would be the failing ones.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