Skip to content

Commit 67d8fee

Browse files
committed
Handle Windows (and other) line endings
2 parents 98d99c8 + 4b87aa0 commit 67d8fee

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/markdown.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ function count_lines( str ) {
160160

161161
// Internal - split source into rough blocks
162162
Markdown.prototype.split_blocks = function splitBlocks( input, startLine ) {
163+
input = input.replace(/(\r\n|\n|\r)/g, '\n');
163164
// [\s\S] matches _anything_ (newline or space)
164165
var re = /([\s\S]+?)($|\n(?:\s*\n|$)+)/g,
165166
blocks = [],

test/regressions.t.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,4 +522,14 @@ test( "inline_autolink", function(t, md) {
522522
t.equivalent( md.processInline( "<foo@bar.com>" ),
523523
[ [ "link", { href: "mailto:foo@bar.com" }, "foo@bar.com" ] ],
524524
"autolink III" );
525-
});
525+
});
526+
527+
test( "line_endings", function(t, md) {
528+
// try to generate this tree with all types of line ending
529+
var tree = [ "markdown", [ "para", "Foo" ], [ "para", "Bar" ] ];
530+
531+
t.equivalent( md.toTree( "Foo\n\nBar", [ "markdown" ] ), tree, "Unix line endings" );
532+
t.equivalent( md.toTree( "Foo\r\n\r\nBar", [ "markdown" ] ), tree, "Windows line endings" );
533+
t.equivalent( md.toTree( "Foo\r\rBar", [ "markdown" ] ), tree, "Mac line endings" );
534+
t.equivalent( md.toTree( "Foo\r\n\nBar", [ "markdown" ] ), tree, "Mixed line endings" );
535+
});

0 commit comments

Comments
 (0)