Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Windows linebreak issues #58

sippeangelo opened this Issue Jun 29, 2012 · 10 comments


None yet
8 participants

I found that markdown.js is having trouble parsing through windows linebreaks.
For example, with code blocks:

    This is code
    Is this also code?

Which produces this output:

<pre><code>This is code</code></pre>

    Is this code?</p>

Is this something the library should handle or do I have to keep normalizing the linebreaks before I parse?


ashb commented Jun 29, 2012

Hmmm good question...

The output is less than ideal, and I can't think of any reason when you'd want a literal \r in the output like that, so I think it is something this module should be dealing with.

Any news regarding this?

tcrosen commented Jul 30, 2012

Also having this issue.

I should mention using Unix-style line breaks in my editor does solve the problem.

I am using it as a nodejs module in order to render blogposts edited in browser. So I have no means (I know of) to change the line break style. In the mean time, I'm replacing \r before rendereing.


XhmikosR commented Aug 9, 2012

I can't break any line if I use CRLF... I found that with LF and 3 trailing spaces, line breaks work fine. This happens with h5ai which is using markdown-js.


matthewkastor commented Nov 15, 2012

Workaround While My Solution is Ignored

I've submitted a patch which fixes this issue but the pull request has been ignored for over a month now. To implement a filter for the markdown you want to parse just do

var input = "# Heading\r\n\r\nParagraph";

// All line endings are converted to `\n` so the issue should not affect you anymore. 
input = input.replace(/(\r\n|\n|\r)/g, '\n');
// input is now equal to: "# Heading\n\nParagraph"

var output = require( "markdown" ).markdown.toHTML( input );
print( output );

The real issue occurs in the Markdown.prototype.split_blocks function defined in lib/markdown.js. That function depends on line endings always being \n and proceeds without warning when other line ending styles are used. Later in the process \r causes issues with parsing and you end up with unexpected results. There should be explicit instructions stating that users are responsible for converting line endings prior to running markdown on their source or, an explicit notification that all line endings will be converted to \n, if my pull request is used.

Reference pull request #64

@evilstreak evilstreak added a commit that referenced this issue Apr 21, 2013

@matthewkastor @evilstreak matthewkastor + evilstreak Issue #58 FIXED
Normalize EOL to `\n` so markdown doesn't gag on it.

evilstreak commented Apr 21, 2013

Fixed by 67d8fee.

@evilstreak evilstreak closed this Apr 21, 2013

I encountered this same problem today while working on a blogging engine. To fix it I used the commend below:

dos2unix postsdirectory/*.md

evilstreak commented May 8, 2013

Hi @qawemlilo. Do you still get the error with the latest code from Github, or is that using 0.4.0? It should be fixed in HEAD now, so if it's not I'd love to know.

Hi @evilstreak, you are right I'm using the npm version which is still on 0.4.0, will fork the latest. This is an awesome project by the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment