diff --git a/app/assets/javascripts/discourse/dialects/dialect.js b/app/assets/javascripts/discourse/dialects/dialect.js index 34ab5b5f0..d5d785e2a 100644 --- a/app/assets/javascripts/discourse/dialects/dialect.js +++ b/app/assets/javascripts/discourse/dialects/dialect.js @@ -181,6 +181,8 @@ function hoistCodeBlocksAndSpans(text) { // replace all "\`" with a single character text = hideBackslashEscapedCharacters(text); + // /!\ the order is important /!\ + //
...
code blocks text = text.replace(/(^\n*|\n\n)
([\s\S]*?)<\/pre>/ig, function(_, before, content) {
     var hash = md5(content);
@@ -188,6 +190,13 @@ function hoistCodeBlocksAndSpans(text) {
     return before + "
" + hash + "
"; }); + // 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");