mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 17:46:05 -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
|
// replace all "\`" with a single character
|
||||||
text = hideBackslashEscapedCharacters(text);
|
text = hideBackslashEscapedCharacters(text);
|
||||||
|
|
||||||
|
// /!\ the order is important /!\
|
||||||
|
|
||||||
// <pre>...</pre> code blocks
|
// <pre>...</pre> code blocks
|
||||||
text = text.replace(/(^\n*|\n\n)<pre>([\s\S]*?)<\/pre>/ig, function(_, before, content) {
|
text = text.replace(/(^\n*|\n\n)<pre>([\s\S]*?)<\/pre>/ig, function(_, before, content) {
|
||||||
var hash = md5(content);
|
var hash = md5(content);
|
||||||
|
@ -188,6 +190,13 @@ function hoistCodeBlocksAndSpans(text) {
|
||||||
return before + "<pre>" + hash + "</pre>";
|
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
|
// markdown code blocks
|
||||||
text = text.replace(/(^\n*|\n\n)((?:(?:[ ]{4}|\t).*\n*)+)/g, function(match, before, content, index) {
|
text = text.replace(/(^\n*|\n\n)((?:(?:[ ]{4}|\t).*\n*)+)/g, function(match, before, content, index) {
|
||||||
// make sure we aren't in a list
|
// make sure we aren't in a list
|
||||||
|
@ -206,13 +215,6 @@ function hoistCodeBlocksAndSpans(text) {
|
||||||
return before + " " + hash + "\n";
|
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 `)
|
// code spans (double & single `)
|
||||||
["``", "`"].forEach(function(delimiter) {
|
["``", "`"].forEach(function(delimiter) {
|
||||||
var regexp = new RegExp("(^|[^`])" + delimiter + "([^`\\n]+?)" + delimiter + "([^`]|$)", "g");
|
var regexp = new RegExp("(^|[^`])" + delimiter + "([^`\\n]+?)" + delimiter + "([^`]|$)", "g");
|
||||||
|
|
Loading…
Reference in a new issue