Fix: dialect block parser should not eat next block's whitespace

This commit is contained in:
Jens Maier 2014-08-26 14:11:23 +02:00
parent d63c6292b3
commit c58565d09f
2 changed files with 5 additions and 1 deletions

View file

@ -462,7 +462,7 @@ Discourse.Dialect = {
before = currentBlock.slice(0, actualEndPos).replace(/\n*$/, ""), before = currentBlock.slice(0, actualEndPos).replace(/\n*$/, ""),
after = currentBlock.slice(actualEndPos + stopLen).replace(/^\n*/, ""); after = currentBlock.slice(actualEndPos + stopLen).replace(/^\n*/, "");
if (before.length > 0) contentBlocks.push(MD.mk_block(before, "", currentBlock.lineNumber)); if (before.length > 0) contentBlocks.push(MD.mk_block(before, "", currentBlock.lineNumber));
if (after.length > 0) next.unshift(MD.mk_block(after, "", currentBlock.lineNumber + countLines(before))); if (after.length > 0) next.unshift(MD.mk_block(after, currentBlock.trailing, currentBlock.lineNumber + countLines(before)));
var emitterResult = args.emitter.call(this, contentBlocks, match, dialect.options); var emitterResult = args.emitter.call(this, contentBlocks, match, dialect.options);
if (emitterResult) { result.push(emitterResult); } if (emitterResult) { result.push(emitterResult); }

View file

@ -371,6 +371,10 @@ test("Code Blocks", function() {
cooked("``` foo bar ```", cooked("``` foo bar ```",
"<p><code>foo bar</code></p>", "<p><code>foo bar</code></p>",
"it tolerates misuse of code block tags as inline code"); "it tolerates misuse of code block tags as inline code");
cooked("```\nline1\n```\n```\nline2\n\nline3\n```",
"<p><pre><code class=\"lang-auto\">line1</code></pre></p>\n\n<p><pre><code class=\"lang-auto\">line2\n\nline3</code></pre></p>",
"it does not consume next block's trailing newlines");
}); });
test("sanitize", function() { test("sanitize", function() {