FIX: Allow backticks in code blocks

This commit is contained in:
Robin Ward 2013-08-26 16:53:10 -04:00
parent 1c3c468675
commit 6c3cb9023c
2 changed files with 12 additions and 6 deletions

View File

@ -49,26 +49,28 @@ Discourse.Dialect.on("register", function(event) {
blockLine = b.lineNumber,
diff = ((typeof blockLine === "undefined") ? lineNumber : blockLine) - lineNumber;
b = b.replace(/ {2}\n/g, "\n");
var n = b.match(/([^`]*)```([^`]*)/m);
var endFound = b.indexOf('```'),
leadingCode = b.slice(0, endFound),
trailingCode = b.slice(endFound+3);
for (var i=1; i<diff; i++) {
codeContents.push("");
}
lineNumber = blockLine + b.split("\n").length - 1;
if (n) {
if (n[2]) {
next.unshift(MD.mk_block(n[2]));
if (endFound !== -1) {
if (trailingCode) {
next.unshift(MD.mk_block(trailingCode));
}
codeContents.push(n[1].replace(/\s+$/, ""));
codeContents.push(leadingCode.replace(/\s+$/, ""));
break;
} else {
codeContents.push(b);
}
}
result.push(['p', ['pre', ['code', {'class': m[1] || 'lang-auto'}, codeContents.join("\n") ]]]);
return result;
}

View File

@ -231,6 +231,10 @@ test("Code Blocks", function() {
cooked("```ruby\ndef self.parse(text)\n\n text\nend\n```",
"<p><pre><code class=\"ruby\">def self.parse(text)\n\n text\nend</code></pre></p>",
"it allows leading spaces on lines in a code block.");
cooked("```ruby\nhello `eviltrout`\n```",
"<p><pre><code class=\"ruby\">hello &#x60;eviltrout&#x60;</code></pre></p>",
"it allows code with backticks in it");
});
test("SanitizeHTML", function() {