mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
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:
parent
0c0cd7db99
commit
43e9448d6e
BIN
dist/showdown.js
vendored
BIN
dist/showdown.js
vendored
Binary file not shown.
BIN
dist/showdown.js.map
vendored
BIN
dist/showdown.js.map
vendored
Binary file not shown.
BIN
dist/showdown.min.js
vendored
BIN
dist/showdown.min.js
vendored
Binary file not shown.
BIN
dist/showdown.min.js.map
vendored
BIN
dist/showdown.min.js.map
vendored
Binary file not shown.
|
@ -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
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
9
src/subParsers/strikethrough.js
Normal file
9
src/subParsers/strikethrough.js
Normal 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;
|
||||
});
|
5
test/features/#164.3.strikethrough.html
Normal file
5
test/features/#164.3.strikethrough.html
Normal 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>
|
5
test/features/#164.3.strikethrough.md
Normal file
5
test/features/#164.3.strikethrough.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
a ~~strikethrough~~ word
|
||||
|
||||
this should~~not be parsed
|
||||
|
||||
~~strike-through text~~
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user