feat(strikethrough): add support for GFM strikethrough

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
This commit is contained in:
Estevão Soares dos Santos 2015-07-11 15:59:06 +01:00
parent 0c0cd7db99
commit 43e9448d6e
11 changed files with 26 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

@ -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

View File

@ -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');

View File

@ -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;
});

View File

@ -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>

View File

@ -0,0 +1,5 @@
a ~~strikethrough~~ word
this should~~not be parsed
~~strike-through text~~

View File

@ -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);
});

View File

@ -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();
}