diff --git a/src/subParsers/codeBlocks.js b/src/subParsers/codeBlocks.js index 25e84ef..6005939 100644 --- a/src/subParsers/codeBlocks.js +++ b/src/subParsers/codeBlocks.js @@ -22,15 +22,21 @@ showdown.subParser('codeBlocks', function (text, options, globals) { var pattern = /(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g; text = text.replace(pattern, function (wholeMatch, m1, m2) { - var codeblock = m1, nextChar = m2; + var codeblock = m1, + nextChar = m2, + end = '\n'; codeblock = showdown.subParser('outdent')(codeblock); codeblock = showdown.subParser('encodeCode')(codeblock); codeblock = showdown.subParser('detab')(codeblock); codeblock = codeblock.replace(/^\n+/g, ''); // trim leading newlines - codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing whitespace + codeblock = codeblock.replace(/\n+$/g, ''); // trim trailing newlines - codeblock = '
' + codeblock + '\n
';
+ if (options.omitExtraWLInCodeBlocks) {
+ end = '';
+ }
+
+ codeblock = '' + codeblock + end + '
';
return showdown.subParser('hashBlock')(codeblock, options, globals) + nextChar;
});