From 13bf8e1e4624e13883f187eab8ebef577ef5114a Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 29 Dec 2014 15:59:23 -0500 Subject: [PATCH] FIX: Markdown bug when a heading preceeded a code block. --- app/assets/javascripts/discourse/dialects/dialect.js | 7 ++++++- test/javascripts/lib/markdown-test.js.es6 | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/dialects/dialect.js b/app/assets/javascripts/discourse/dialects/dialect.js index 32b6e7692be..66b72994b4e 100644 --- a/app/assets/javascripts/discourse/dialects/dialect.js +++ b/app/assets/javascripts/discourse/dialects/dialect.js @@ -421,7 +421,12 @@ Discourse.Dialect = { // just give up if there's no stop tag in this or any next block args.stop.lastIndex = block.length - trailing.length; if (!args.stop.exec(block) && lastChance()) { return; } - if (leading.length > 0) { result.push(['p'].concat(this.processInline(leading))); } + if (leading.length > 0) { + var parsedLeading = this.processBlock(MD.mk_block(leading), []); + if (parsedLeading && parsedLeading[0]) { + result.push(parsedLeading[0]); + } + } if (trailing.length > 0) { next.unshift(MD.mk_block(trailing, block.trailing, block.lineNumber + countLines(leading) + (match[2] ? match[2].length : 0) - trailing.length)); diff --git a/test/javascripts/lib/markdown-test.js.es6 b/test/javascripts/lib/markdown-test.js.es6 index fcd2ee7b83d..72203067e38 100644 --- a/test/javascripts/lib/markdown-test.js.es6 +++ b/test/javascripts/lib/markdown-test.js.es6 @@ -398,6 +398,8 @@ test("Code Blocks", function() { cooked(" [quote]test[/quote]", "
[quote]test[/quote]
", "it does not parse other block types in markdown code blocks"); + + cooked("## a\nb\n```\nc\n```", "

a

\n\n

c

", "it handles headings with code blocks after them."); }); test("sanitize", function() {