diff --git a/core/shared/lib/showdown/extensions/ghostfootnotes.js b/core/shared/lib/showdown/extensions/ghostfootnotes.js index b491504451..24d4c9611a 100644 --- a/core/shared/lib/showdown/extensions/ghostfootnotes.js +++ b/core/shared/lib/showdown/extensions/ghostfootnotes.js @@ -79,12 +79,25 @@ function replaceEndFootnotes(text, converter) { } // Extract pre blocks + text = text.replace(/<(pre|code)>[\s\S]*?<\/(\1)>/gim, function (x) { + var hash = hashId(); + preExtractions[hash] = x; + return '{gfm-js-extract-pre-' + hash + '}'; + }, 'm'); + text = text.replace(/```[\s\S]*?\n```/gim, function (x) { var hash = hashId(); preExtractions[hash] = x; return '{gfm-js-extract-pre-' + hash + '}'; }, 'm'); + // Extract code blocks + text = text.replace(/`[\s\S]*?`/gim, function (x) { + var hash = hashId(); + preExtractions[hash] = x; + return '{gfm-js-extract-pre-' + hash + '}'; + }, 'm'); + text = replaceInlineFootnotes(text); text = replaceEndFootnotes(text, converter); diff --git a/core/test/unit/showdown_footnotes_spec.js b/core/test/unit/showdown_footnotes_spec.js index f3ea4089df..079edf067f 100644 --- a/core/test/unit/showdown_footnotes_spec.js +++ b/core/test/unit/showdown_footnotes_spec.js @@ -103,4 +103,40 @@ describe('Ghost footnotes showdown extension', function () { processedMarkup.should.match(testPhrase.output); }); + + it('should show markdown inside code block', function () { + var testPhrase = { + input: '[^n]<\/code>', + output: '[^n]<\/code>' + }, processedMarkup = _ConvertPhrase(testPhrase.input); + + processedMarkup.should.match(testPhrase.output); + }); + + it('should show markdown inside pre block', function () { + var testPhrase = { + input: '
[^n]<\/pre>',
+            output: '
[^n]<\/pre>'
+        }, processedMarkup = _ConvertPhrase(testPhrase.input);
+
+        processedMarkup.should.match(testPhrase.output);
+    });
+
+    it('should show markdown inside single tick', function () {
+        var testPhrase = {
+            input: '`[^n]`',
+            output: '`[^n]`'
+        }, processedMarkup = _ConvertPhrase(testPhrase.input);
+
+        processedMarkup.should.match(testPhrase.output);
+    });
+
+    it('should show markdown inside triple tick', function () {
+        var testPhrase = {
+            input: '```[^n]```',
+            output: '```[^n]```'
+        }, processedMarkup = _ConvertPhrase(testPhrase.input);
+
+        processedMarkup.should.match(testPhrase.output);
+    });
 });