FIX: Broken MDTest + Fix for removing leading spaces in a code block

This commit is contained in:
Robin Ward 2014-02-11 17:27:01 -05:00
parent 7a85e06119
commit 3d62df51a6
2 changed files with 17 additions and 4 deletions

View File

@ -29,7 +29,20 @@ Discourse.Dialect.replaceBlock({
// Ensure that content in a code block is fully escaped. This way it's not white listed // 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. // and we can use HTML and Javascript examples.
Discourse.Dialect.postProcessTag('code', function (contents) { Discourse.Dialect.on('parseNode', function (event) {
return Handlebars.Utils.escapeExpression(contents.replace(/^ +| +$/g,'')); 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,''));
}
});

View File

@ -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 it and indent it, and Markdown will handle the hassle of encoding the
ampersands and angle brackets. For example, this:</p> ampersands and angle brackets. For example, this:</p>
<pre><code>&lt;div class=&quot;footer&quot;&gt; <pre><code> &lt;div class=&quot;footer&quot;&gt;
&amp;copy; 2004 Foo Corporation &amp;copy; 2004 Foo Corporation
&lt;/div&gt; &lt;/div&gt;
</code></pre> </code></pre>