Skip to content

With CR-only line endings, ExtractBody/RemoveFrontmatter/ReplaceFrontmatter keep the blank lines after the header ("\r\rBody" instead of "Body") #184

Description

@matt-edmondson

What's wrong

TrimBody (Frontmatter/Frontmatter.cs:502-519) only advances past leading blank lines on '\n'. SplitLines (Frontmatter.cs:465) documents support for CRLF, LF and CR, so CR-only documents parse fine but their leading blank body lines are never trimmed.

Repro (main @ 23c87b1)

Frontmatter.ExtractBody("---\rtitle: x\r---\r\r\rBody\r");        // "\r\rBody"   (LF equivalent gives "Body")
Frontmatter.RemoveFrontmatter("---\rtitle: x\r---\r\r\rBody\r");  // "\r\rBody" + NewLine
Frontmatter.ReplaceFrontmatter(...)                                // writes "---\ntitle: y\n---\n\r\rBody"

Expected: "Body", the same as for LF and CRLF input.

Why it matters

The output depends on line-ending style, and callers get stray blank lines at the start of the body. Low impact since CR-only files are rare, but it contradicts the line-ending support SplitLines advertises.

Suggested fix

In TrimBody, treat both terminators as line ends: if (c is '\n' or '\r') start = i + 1;. For CRLF this still lands after the \n.

Acceptance: ExtractBody/RemoveFrontmatter return the same body for CR, LF and CRLF versions of a document with blank lines after the header.

Activity

  1. matt-edmondson commented on Oct 6, 2026

    @matt-edmondson
    ContributorAuthor

    Triage

    • Category: Bug
    • Priority: Low. The output depends on line-ending style, but CR-only documents are rare and the only effect is stray leading blank lines in the body. Nothing is lost.
    • Suggested area / assignment: Frontmatter/Frontmatter.cs, TrimBody (and its agreement with SplitLines)
    • Duplicates / related: None found.
    • In progress: No open PR covers it.

    Recommended next step: Apply the one-line c is '\n' or '\r' change in TrimBody. Add a test that runs CR, LF and CRLF versions of the same document through ExtractBody and RemoveFrontmatter.


    Generated by Claude Code

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

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions