mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
FIX: code block hoisting bug
This commit is contained in:
parent
12d59d13a7
commit
9061c26e52
1 changed files with 9 additions and 7 deletions
|
@ -181,6 +181,8 @@ function hoistCodeBlocksAndSpans(text) {
|
|||
// replace all "\`" with a single character
|
||||
text = hideBackslashEscapedCharacters(text);
|
||||
|
||||
// /!\ the order is important /!\
|
||||
|
||||
// <pre>...</pre> code blocks
|
||||
text = text.replace(/(^\n*|\n\n)<pre>([\s\S]*?)<\/pre>/ig, function(_, before, content) {
|
||||
var hash = md5(content);
|
||||
|
@ -188,6 +190,13 @@ function hoistCodeBlocksAndSpans(text) {
|
|||
return before + "<pre>" + hash + "</pre>";
|
||||
});
|
||||
|
||||
// fenced code blocks (AKA GitHub code blocks)
|
||||
text = text.replace(/(^\n*|\n\n)```([a-z0-9\-]*)\n([\s\S]*?)\n```/g, function(_, before, language, content) {
|
||||
var hash = md5(content);
|
||||
hoisted[hash] = escape(showBackslashEscapedCharacters(content.trim()));
|
||||
return before + "```" + language + "\n" + hash + "\n```";
|
||||
});
|
||||
|
||||
// markdown code blocks
|
||||
text = text.replace(/(^\n*|\n\n)((?:(?:[ ]{4}|\t).*\n*)+)/g, function(match, before, content, index) {
|
||||
// make sure we aren't in a list
|
||||
|
@ -206,13 +215,6 @@ function hoistCodeBlocksAndSpans(text) {
|
|||
return before + " " + hash + "\n";
|
||||
});
|
||||
|
||||
// fenced code blocks (AKA GitHub code blocks)
|
||||
text = text.replace(/(^\n*|\n\n)```([a-z0-9\-]*)\n([\s\S]*?)\n```/g, function(_, before, language, content) {
|
||||
var hash = md5(content);
|
||||
hoisted[hash] = escape(showBackslashEscapedCharacters(content.trim()));
|
||||
return before + "```" + language + "\n" + hash + "\n```";
|
||||
});
|
||||
|
||||
// code spans (double & single `)
|
||||
["``", "`"].forEach(function(delimiter) {
|
||||
var regexp = new RegExp("(^|[^`])" + delimiter + "([^`\\n]+?)" + delimiter + "([^`]|$)", "g");
|
||||
|
|
Loading…
Reference in a new issue