Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Commit

Permalink
Add support for CR and CRLF line endings
Browse files Browse the repository at this point in the history
fixes #5
  • Loading branch information
fredemmott committed Jun 12, 2018
1 parent 4c20c9f commit c5f64b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/unparsed-blocks/parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function parse(
string $markdown,
): Document {
$lines = $markdown
|> Str\replace($$, "\r\n", "\n")
|> Str\replace($$, "\r", "\n")
|> Str\split($$, "\n")
|> (C\lastx($$) === '' ? Vec\slice($$, 0, C\count($$) - 1) : $$)
|> Vec\map($$, $line ==> tuple(0, $line))
Expand Down
15 changes: 15 additions & 0 deletions tests/EdgeCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ public function getManualExamples(
'*foo __bar *baz bim__ bam*',
"<p><em>foo <strong>bar *baz bim</strong> bam</em></p>\n",
),
// CR
tuple(
"CR Foo\x0d\x0d> Bar\x0d\x0dBaz",
"<p>CR Foo</p>\n<blockquote>\n<p>Bar</p>\n</blockquote>\n<p>Baz</p>\n",
),
// LF
tuple(
"LF Foo\x0a\x0a> Bar\x0a\x0aBaz",
"<p>LF Foo</p>\n<blockquote>\n<p>Bar</p>\n</blockquote>\n<p>Baz</p>\n",
),
// CRLF
tuple(
"CRLF Foo\x0d\x0a\x0d\x0a> Bar\x0d\x0a\x0d\x0aBaz",
"<p>CRLF Foo</p>\n<blockquote>\n<p>Bar</p>\n</blockquote>\n<p>Baz</p>\n",
),
];
}

Expand Down

0 comments on commit c5f64b5

Please sign in to comment.