Skip to content

Commit

Permalink
fix(options.omitExtraWLInCodeBlocks): fix for options.omitExtraWLInCo…
Browse files Browse the repository at this point in the history
…deBlocks only applying in gitHub flavoured code blocks
  • Loading branch information
tivie committed May 26, 2015
1 parent ddd6011 commit e6f40e1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/subParsers/codeBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<pre><code>' + codeblock + '\n</code></pre>';
if (options.omitExtraWLInCodeBlocks) {
end = '';
}

codeblock = '<pre><code>' + codeblock + end + '</code></pre>';

return showdown.subParser('hashBlock')(codeblock, options, globals) + nextChar;
});
Expand Down

0 comments on commit e6f40e1

Please sign in to comment.