diff --git a/app/assets/javascripts/discourse/dialects/github_code_dialect.js b/app/assets/javascripts/discourse/dialects/github_code_dialect.js index c4f38f814a9..d3898bc24ce 100644 --- a/app/assets/javascripts/discourse/dialects/github_code_dialect.js +++ b/app/assets/javascripts/discourse/dialects/github_code_dialect.js @@ -29,7 +29,20 @@ Discourse.Dialect.replaceBlock({ // Ensure that content in a code block is fully escaped. This way it's not white listed // and we can use HTML and Javascript examples. -Discourse.Dialect.postProcessTag('code', function (contents) { - return Handlebars.Utils.escapeExpression(contents.replace(/^ +| +$/g,'')); -}); +Discourse.Dialect.on('parseNode', function (event) { + var node = event.node, + path = event.path; + if (node[0] === 'code') { + var contents = node[node.length-1], + regexp; + + if (path && path[path.length-1] && path[path.length-1][0] && path[path.length-1][0] === "pre") { + regexp = / +$/g; + + } else { + regexp = /^ +| +$/g; + } + node[node.length-1] = Handlebars.Utils.escapeExpression(contents.replace(regexp,'')); + } +}); diff --git a/test/javascripts/mdtest/fixtures/Markdown Documentation - Syntax.xhtml b/test/javascripts/mdtest/fixtures/Markdown Documentation - Syntax.xhtml index 5c6b9e32b7c..2a83541bdcd 100755 --- a/test/javascripts/mdtest/fixtures/Markdown Documentation - Syntax.xhtml +++ b/test/javascripts/mdtest/fixtures/Markdown Documentation - Syntax.xhtml @@ -524,7 +524,7 @@ easy to include example HTML source code using Markdown -- just paste it and indent it, and Markdown will handle the hassle of encoding the ampersands and angle brackets. For example, this:
-<div class="footer">
+ <div class="footer">
© 2004 Foo Corporation
</div>