Skip to content

fix: normalize CRLF/CR line endings to LF (fixes #69) - #122

Open
Ultroncn wants to merge 1 commit into
developit:mainfrom
Ultroncn:fix/crlf-line-endings
Open

Ultroncn wants to merge 1 commit into
developit:mainfrom
Ultroncn:fix/crlf-line-endings

Conversation

@Ultroncn

Copy link
Copy Markdown

Problem

parse() only understands LF (\\n) line endings. Input with Windows CRLF (\\r\\n) line endings passes through untouched: no <br />, headings/lists after CRLF lines are not recognized. Reported in #69 (reporter worked around it with a pre-parse .replace(), and a second user confirmed it).

Reproduction

snarkdown('hello\\r\\n\\r\\nworld')
// before: "hello\\r\\n\\r\\nworld"  (raw CR/LF leaked into the output)
// after:  "hello<br />world"

snarkdown('# hi\\r\\n\\r\\ntext\\r\\nmore')
// before: "<h1>hi</h1>\\r\\n\\r\\ntext\\r\\nmore"
// after:  "<h1>hi</h1>text\\nmore"  (same as the LF input)

Change

One line in src/index.js, at the top of parse() — normalize line endings before any tokenizing:

md = md.replace(/\\r\\n?/g, '\\n')...

This also normalizes lone CR (\\r, classic Mac) line endings, and applies inside fenced/indented code blocks too, so CRLF input now behaves exactly like LF input.

Tests

Added a test in test/index.js (line breaks suite) covering CRLF, lone CR, and a CRLF heading. Verified it fails on the old code:

  • new test on old code: 1 failing (expected 'Something with\\r\\n\\r\\na line break' to equal 'Something with<br />a line break')
  • full suite after the fix: npm test (eslint + mocha) — 34 passing, 0 failing

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T00:08:08.524564Z 42024e2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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.

1 participant