feat(ghCodeBlocks): add option to disable GH codeblocks

GFM support fenced codeblocks. Showdown, since very early, adopted this too.
It is now possible to disable GFM codeblocks with the option "ghCodeBlocks" set to false.
It is enabled by default
This commit is contained in:
Estevão Soares dos Santos 2015-07-11 20:33:11 +01:00
parent 5ec75c459b
commit c33f98884b
10 changed files with 29 additions and 2 deletions

BIN
dist/showdown.js vendored

Binary file not shown.

BIN
dist/showdown.js.map vendored

Binary file not shown.

BIN
dist/showdown.min.js vendored

Binary file not shown.

Binary file not shown.

View File

@ -16,7 +16,8 @@ var showdown = {},
literalMidWordUnderscores: false,
strikethrough: false,
tables: false,
tablesHeaderId: false
tablesHeaderId: false,
ghCodeBlocks: true // true due to historical reasons
},
globalOptions = JSON.parse(JSON.stringify(defaultOptions)); //clone default options out of laziness =P

View File

@ -11,6 +11,11 @@
showdown.subParser('githubCodeBlocks', function (text, options, globals) {
'use strict';
// early exit if option is not enabled
if (!options.ghCodeBlocks) {
return text;
}
text += '~0';
text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, m1, m2) {

View File

@ -0,0 +1,9 @@
<p>this is some text</p>
<p><code>php
function thisThing() {
echo "some weird formatted code!";
}
</code></p>
<p>some other text</p>

View File

@ -0,0 +1,9 @@
this is some text
```php
function thisThing() {
echo "some weird formatted code!";
}
```
some other text

View File

@ -27,7 +27,8 @@ describe('showdown.options', function () {
literalMidWordUnderscores: false,
strikethrough: false,
tables: false,
tablesHeaderId: false
tablesHeaderId: false,
ghCodeBlocks: true
};
expect(showdown.getDefaultOptions()).to.be.eql(opts);
});

View File

@ -21,6 +21,8 @@ describe('makeHtml() features testsuite', function () {
converter = new showdown.Converter({literalMidWordUnderscores: true});
} else if (testsuite[i].name === '#164.3.strikethrough') {
converter = new showdown.Converter({strikethrough: true});
} else if (testsuite[i].name === 'disable_gh_codeblocks') {
converter = new showdown.Converter({ghCodeBlocks: false});
} else {
converter = new showdown.Converter();
}