From c58565d09f350734c9a1a47f8ad3d5473959f0dc Mon Sep 17 00:00:00 2001 From: Jens Maier Date: Tue, 26 Aug 2014 14:11:23 +0200 Subject: [PATCH] Fix: dialect block parser should not eat next block's whitespace --- app/assets/javascripts/discourse/dialects/dialect.js | 2 +- test/javascripts/lib/markdown-test.js.es6 | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/dialects/dialect.js b/app/assets/javascripts/discourse/dialects/dialect.js index 749b289fc..07ebc7947 100644 --- a/app/assets/javascripts/discourse/dialects/dialect.js +++ b/app/assets/javascripts/discourse/dialects/dialect.js @@ -462,7 +462,7 @@ Discourse.Dialect = { before = currentBlock.slice(0, actualEndPos).replace(/\n*$/, ""), after = currentBlock.slice(actualEndPos + stopLen).replace(/^\n*/, ""); 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); if (emitterResult) { result.push(emitterResult); } diff --git a/test/javascripts/lib/markdown-test.js.es6 b/test/javascripts/lib/markdown-test.js.es6 index 981d4eceb..067930e7d 100644 --- a/test/javascripts/lib/markdown-test.js.es6 +++ b/test/javascripts/lib/markdown-test.js.es6 @@ -371,6 +371,10 @@ test("Code Blocks", function() { cooked("``` foo bar ```", "

foo bar

", "it tolerates misuse of code block tags as inline code"); + + cooked("```\nline1\n```\n```\nline2\n\nline3\n```", + "

line1

\n\n

line2\n\nline3

", + "it does not consume next block's trailing newlines"); }); test("sanitize", function() {