evilstreak / markdown-js

A Markdown parser for javascript
7.69k stars 863 forks source link

two blank lines break the code block #292

Open ckcks12 opened 7 years ago

ckcks12 commented 7 years ago

original text

function foo() {
    console.log(this);
}
// below two blank lines cause a bug

using markdown

markdown.toHTML('```\n\
function foo() {\n\
    console.log(this);\n\
}\n\
// below two blank lines cause a bug\n\
\n\
\n\
```')

converted

"<p><code></code>`
function foo() {
    console.log(this);
}
// below two blank lines cause a bug</p>

<p><code></code>`</p>"

Is that a bug or my mistake?

ckcks12 commented 7 years ago

not only trailing position but also anywhere the two blank lines exist the code block be broken ...

nicecp commented 6 years ago

I have meet the same issue, without line breaks in code

clChenLiang commented 6 years ago

I have try to revise the output of markdown.toHTML() function. here the simple code:

    html.replace(/<code><\/code>\`(?=[^<])/g,'<code>');
    html.replace(/<code><\/code>\`(?=<)/g, '<\/code>');
ckcks12 commented 6 years ago

Of course there are more workarounds for this but we want it be fixed, not more cheats.

icarito commented 6 years ago

Perhaps we could start by writing a test that fails... I'll try to get to it. I share your pain - Tiddlywiki uses this library! Also worth checking out if a fork has this fixed.