Skip to content

Commit

Permalink
feat(ghCodeBlocks): add option to disable GH codeblocks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tivie committed Jul 11, 2015
1 parent 5ec75c4 commit c33f988
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 6 deletions.
8 changes: 7 additions & 1 deletion dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/showdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/subParsers/githubCodeBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions test/features/disable_gh_codeblocks.html
Original file line number Diff line number Diff line change
@@ -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>
9 changes: 9 additions & 0 deletions test/features/disable_gh_codeblocks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
this is some text

```php
function thisThing() {
echo "some weird formatted code!";
}
```

some other text
3 changes: 2 additions & 1 deletion test/node/showdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down
2 changes: 2 additions & 0 deletions test/node/testsuite.features.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit c33f988

Please sign in to comment.