Skip to content

Commit

Permalink
Handle Windows (and other) line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
evilstreak committed Apr 21, 2013
2 parents 98d99c8 + 4b87aa0 commit 67d8fee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ function count_lines( str ) {

// Internal - split source into rough blocks
Markdown.prototype.split_blocks = function splitBlocks( input, startLine ) {
input = input.replace(/(\r\n|\n|\r)/g, '\n');
// [\s\S] matches _anything_ (newline or space)
var re = /([\s\S]+?)($|\n(?:\s*\n|$)+)/g,
blocks = [],
Expand Down
12 changes: 11 additions & 1 deletion test/regressions.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,4 +522,14 @@ test( "inline_autolink", function(t, md) {
t.equivalent( md.processInline( "<foo@bar.com>" ),
[ [ "link", { href: "mailto:foo@bar.com" }, "foo@bar.com" ] ],
"autolink III" );
});
});

test( "line_endings", function(t, md) {
// try to generate this tree with all types of line ending
var tree = [ "markdown", [ "para", "Foo" ], [ "para", "Bar" ] ];

t.equivalent( md.toTree( "Foo\n\nBar", [ "markdown" ] ), tree, "Unix line endings" );
t.equivalent( md.toTree( "Foo\r\n\r\nBar", [ "markdown" ] ), tree, "Windows line endings" );
t.equivalent( md.toTree( "Foo\r\rBar", [ "markdown" ] ), tree, "Mac line endings" );
t.equivalent( md.toTree( "Foo\r\n\nBar", [ "markdown" ] ), tree, "Mixed line endings" );
});

0 comments on commit 67d8fee

Please sign in to comment.