From 42024e2f8cf0d8bb08a30bd5d6d862d4784de447 Mon Sep 17 00:00:00 2001 From: Ultroncn <82553854+Ultroncn@users.noreply.github.com> Date: Wed, 18 Nov 2026 00:05:55 +0000 Subject: [PATCH] fix: normalize CRLF/CR line endings to LF (fixes #69) --- src/index.js | 2 +- test/index.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 3938c5c..1a7ec7e 100644 --- a/src/index.js +++ b/src/index.js @@ -47,7 +47,7 @@ export default function parse(md, prevLinks) { return str; } - md = md.replace(/^\[(.+?)\]:\s*(.+)$/gm, (s, name, url) => { + md = md.replace(/\r\n?/g, '\n').replace(/^\[(.+?)\]:\s*(.+)$/gm, (s, name, url) => { links[name.toLowerCase()] = url; return ''; }).replace(/^\n+|\n+$/g, ''); diff --git a/test/index.js b/test/index.js index 5262b16..ba15520 100644 --- a/test/index.js +++ b/test/index.js @@ -102,6 +102,12 @@ describe('snarkdown()', () => { it('parses two spaces as a line break', () => { expect(snarkdown('Something with \na line break')).to.equal('Something with
a line break'); }); + + it('parses CRLF line endings like LF line endings (fixes #69)', () => { + expect(snarkdown('Something with\r\n\r\na line break')).to.equal('Something with
a line break'); + expect(snarkdown('Something with\r\ra line break')).to.equal('Something with
a line break'); + expect(snarkdown('# Title\r\n\r\ntext')).to.equal('

Title

text'); + }); }); describe('code & quotes', () => {