Skip to content

Commit

Permalink
feat(strikethrough): add support for GFM strikethrough
Browse files Browse the repository at this point in the history
Github Flavored Markdown supports strikethrough (`<del>`) syntax using double tilde `~~` delimiters.
This commit adds this feature to showdown through an option called "strikethrough".

Related to #164
  • Loading branch information
tivie committed Jul 11, 2015
1 parent 0c0cd7d commit 43e9448
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 6 deletions.
14 changes: 13 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
Expand Up @@ -13,7 +13,8 @@ var showdown = {},
headerLevelStart: 1,
parseImgDimensions: false,
simplifiedAutoLink: false,
literalMidWordUnderscores: false
literalMidWordUnderscores: false,
strikethrough: false
},
globalOptions = JSON.parse(JSON.stringify(defaultOptions)); //clone default options out of laziness =P

Expand Down
1 change: 1 addition & 0 deletions src/subParsers/spanGamut.js
Expand Up @@ -20,6 +20,7 @@ showdown.subParser('spanGamut', function (text, options, globals) {
text = showdown.subParser('autoLinks')(text, options, globals);
text = showdown.subParser('encodeAmpsAndAngles')(text, options, globals);
text = showdown.subParser('italicsAndBold')(text, options, globals);
text = showdown.subParser('strikethrough')(text, options, globals);

// Do hard breaks:
text = text.replace(/ +\n/g, ' <br />\n');
Expand Down
9 changes: 9 additions & 0 deletions src/subParsers/strikethrough.js
@@ -0,0 +1,9 @@
showdown.subParser('strikethrough', function (text, options) {
'use strict';

if (options.strikethrough) {
text = text.replace(/(?:~T){2}([^~]+)(?:~T){2}/g, '<del>$1</del>');
}

return text;
});
5 changes: 5 additions & 0 deletions test/features/#164.3.strikethrough.html
@@ -0,0 +1,5 @@
<p>a <del>strikethrough</del> word</p>

<p>this should~~not be parsed</p>

<p><del>strike-through text</del></p>
5 changes: 5 additions & 0 deletions test/features/#164.3.strikethrough.md
@@ -0,0 +1,5 @@
a ~~strikethrough~~ word

this should~~not be parsed

~~strike-through text~~
3 changes: 2 additions & 1 deletion test/node/showdown.js
Expand Up @@ -24,7 +24,8 @@ describe('showdown.options', function () {
headerLevelStart: 1,
parseImgDimensions: false,
simplifiedAutoLink: false,
literalMidWordUnderscores: false
literalMidWordUnderscores: false,
strikethrough: false
};
expect(showdown.getDefaultOptions()).to.be.eql(opts);
});
Expand Down
2 changes: 2 additions & 0 deletions test/node/testsuite.features.js
Expand Up @@ -18,6 +18,8 @@ describe('makeHtml() features testsuite', function () {
converter = new showdown.Converter({simplifiedAutoLink: true});
} else if (testsuite[i].name === '#164.2.disallow_underscore_emphasis_mid_word') {
converter = new showdown.Converter({literalMidWordUnderscores: true});
} else if (testsuite[i].name === '#164.3.strikethrough') {
converter = new showdown.Converter({strikethrough: true});
} else {
converter = new showdown.Converter();
}
Expand Down

0 comments on commit 43e9448

Please sign in to comment.