Skip to content

Commit c33f988

Browse files
committed
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
1 parent 5ec75c4 commit c33f988

File tree

10 files changed

+39
-6
lines changed

10 files changed

+39
-6
lines changed

dist/showdown.js

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/showdown.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ var showdown = {},
1616
literalMidWordUnderscores: false,
1717
strikethrough: false,
1818
tables: false,
19-
tablesHeaderId: false
19+
tablesHeaderId: false,
20+
ghCodeBlocks: true // true due to historical reasons
2021
},
2122
globalOptions = JSON.parse(JSON.stringify(defaultOptions)); //clone default options out of laziness =P
2223

src/subParsers/githubCodeBlocks.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
showdown.subParser('githubCodeBlocks', function (text, options, globals) {
1212
'use strict';
1313

14+
// early exit if option is not enabled
15+
if (!options.ghCodeBlocks) {
16+
return text;
17+
}
18+
1419
text += '~0';
1520

1621
text = text.replace(/(?:^|\n)```(.*)\n([\s\S]*?)\n```/g, function (wholeMatch, m1, m2) {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<p>this is some text</p>
2+
3+
<p><code>php
4+
function thisThing() {
5+
echo "some weird formatted code!";
6+
}
7+
</code></p>
8+
9+
<p>some other text</p>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
this is some text
2+
3+
```php
4+
function thisThing() {
5+
echo "some weird formatted code!";
6+
}
7+
```
8+
9+
some other text

test/node/showdown.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ describe('showdown.options', function () {
2727
literalMidWordUnderscores: false,
2828
strikethrough: false,
2929
tables: false,
30-
tablesHeaderId: false
30+
tablesHeaderId: false,
31+
ghCodeBlocks: true
3132
};
3233
expect(showdown.getDefaultOptions()).to.be.eql(opts);
3334
});

test/node/testsuite.features.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ describe('makeHtml() features testsuite', function () {
2121
converter = new showdown.Converter({literalMidWordUnderscores: true});
2222
} else if (testsuite[i].name === '#164.3.strikethrough') {
2323
converter = new showdown.Converter({strikethrough: true});
24+
} else if (testsuite[i].name === 'disable_gh_codeblocks') {
25+
converter = new showdown.Converter({ghCodeBlocks: false});
2426
} else {
2527
converter = new showdown.Converter();
2628
}

0 commit comments

Comments
 (0)