From aa41a9ce700a1a39d13c189d0f769694bce603aa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9gis=20Hanol?= ...
code blocks
text = text.replace(/(^\n*|\n\n)([\s\S]*?)<\/pre>/ig, function(_, before, content) {
var hash = md5(content);
- hoisted[hash] = escape(showBackslashEscapedCharacters(content.trim()));
+ hoisted[hash] = escape(showBackslashEscapedCharacters(removeEmptyLines(content)));
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()));
+ hoisted[hash] = escape(showBackslashEscapedCharacters(removeEmptyLines(content)));
return before + "```" + language + "\n" + hash + "\n```";
});
@@ -209,9 +214,7 @@ function hoistCodeBlocksAndSpans(text) {
}
// we can safely hoist the code block
var hash = md5(content);
- // only remove trailing whitespace
- content = content.replace(/\s+$/, "");
- hoisted[hash] = escape(outdent(showBackslashEscapedCharacters(content)));
+ hoisted[hash] = escape(outdent(showBackslashEscapedCharacters(removeEmptyLines(content))));
return before + " " + hash + "\n";
});
diff --git a/test/javascripts/lib/markdown-test.js.es6 b/test/javascripts/lib/markdown-test.js.es6
index 6ae727c5504..f5859165f18 100644
--- a/test/javascripts/lib/markdown-test.js.es6
+++ b/test/javascripts/lib/markdown-test.js.es6
@@ -529,6 +529,6 @@ test("censoring", function() {
test("code blocks/spans hoisting", function() {
cooked("```\n\n some code\n```",
- "some code
some code
",
"it works when nesting standard markdown code blocks within a fenced code block");
});