mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: Allow backticks in code blocks
This commit is contained in:
parent
1c3c468675
commit
6c3cb9023c
@ -49,26 +49,28 @@ Discourse.Dialect.on("register", function(event) {
|
|||||||
blockLine = b.lineNumber,
|
blockLine = b.lineNumber,
|
||||||
diff = ((typeof blockLine === "undefined") ? lineNumber : blockLine) - lineNumber;
|
diff = ((typeof blockLine === "undefined") ? lineNumber : blockLine) - lineNumber;
|
||||||
|
|
||||||
b = b.replace(/ {2}\n/g, "\n");
|
var endFound = b.indexOf('```'),
|
||||||
var n = b.match(/([^`]*)```([^`]*)/m);
|
leadingCode = b.slice(0, endFound),
|
||||||
|
trailingCode = b.slice(endFound+3);
|
||||||
|
|
||||||
for (var i=1; i<diff; i++) {
|
for (var i=1; i<diff; i++) {
|
||||||
codeContents.push("");
|
codeContents.push("");
|
||||||
}
|
}
|
||||||
lineNumber = blockLine + b.split("\n").length - 1;
|
lineNumber = blockLine + b.split("\n").length - 1;
|
||||||
|
|
||||||
if (n) {
|
if (endFound !== -1) {
|
||||||
if (n[2]) {
|
if (trailingCode) {
|
||||||
next.unshift(MD.mk_block(n[2]));
|
next.unshift(MD.mk_block(trailingCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
codeContents.push(n[1].replace(/\s+$/, ""));
|
codeContents.push(leadingCode.replace(/\s+$/, ""));
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
codeContents.push(b);
|
codeContents.push(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
result.push(['p', ['pre', ['code', {'class': m[1] || 'lang-auto'}, codeContents.join("\n") ]]]);
|
result.push(['p', ['pre', ['code', {'class': m[1] || 'lang-auto'}, codeContents.join("\n") ]]]);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -231,6 +231,10 @@ test("Code Blocks", function() {
|
|||||||
cooked("```ruby\ndef self.parse(text)\n\n text\nend\n```",
|
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>",
|
"<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.");
|
"it allows leading spaces on lines in a code block.");
|
||||||
|
|
||||||
|
cooked("```ruby\nhello `eviltrout`\n```",
|
||||||
|
"<p><pre><code class=\"ruby\">hello `eviltrout`</code></pre></p>",
|
||||||
|
"it allows code with backticks in it");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("SanitizeHTML", function() {
|
test("SanitizeHTML", function() {
|
||||||
|
Loading…
Reference in New Issue
Block a user