Describe the bug
marked('<h2>foo bar</h2><pre>foo\n\nbar\n</pre>')
"<h2>foo bar</h2><pre>foo
<p>bar
</pre></p>
"
Expected behavior
return this:
"<h2>foo bar</h2><pre>foo
bar
</pre>
"
What version of marked are you using.
It seems to be working correctly in the demo
I just grabbed the latrst from github
Am 28. Mai 2018 00:30:24 MESZ schrieb Tony Brix notifications@github.com:
What version of marked are you using.
It seems to be working correctly in the
demo--
You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub:
https://github.com/markedjs/marked/issues/1277#issuecomment-392381820
@Sorunome GitHub is not a good place to grab code since the code is always changing and might break.
Try the latest release v0.4.0 and see if that works for you: https://cdn.jsdelivr.net/npm/[email protected]/marked.min.js
Nope, still doesn't work for me. I didn't think may be related, but yeah i'm also using this:
var markedRenderer = new marked.Renderer();
markedRenderer.code = function(code, lang) {
return '<pre>'+code+'</pre>';
};
markedRenderer.heading = function(text, level, raw) {
level++; // we don't allow h1, so we actually do h2....whatever
return '<h' + level + '>' + text + '</h' + level + '>\n';
};
marked.setOptions({
renderer: markedRenderer,
headerIds: false,
});
I tried from the command line and was able to reproduce.
var str = '<h2>foo bar</h2><pre>foo\n\nbar\n</pre>';
marked(str);
/*
"<h2>foo bar</h2><pre>foo
<p>bar
</pre></p>
"
*/
The p tag is wrapping the pre for some strange reason.
This is actually valid output according to the CommonMark spec:
Your first line is parsed as an HTML block (see Condition # 6 in the spec). The end condition for it is:
line is followed by a blank line.
which is exacly what we have here. Thus the following text bar\n</pre> is treated as a paragraph and is wrapped in p tag
Commonmark playground:
https://spec.commonmark.org/dingus/?text=%3Ca%20%20%2F%3E%3Cb2%0Adata%3D%22foo%22%20%3E%0A
@RomanGotsiy You're right, this is exactly the same output as commonmark 馃憤
Closing.