From e6f40e190c9eb4aa14f5cba244db93daa363e040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Estev=C3=A3o=20Soares=20dos=20Santos?= Date: Tue, 26 May 2015 19:57:36 +0100 Subject: [PATCH] fix(options.omitExtraWLInCodeBlocks): fix for options.omitExtraWLInCodeBlocks only applying in gitHub flavoured code blocks --- src/subParsers/codeBlocks.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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; });