Skip to content

Commit

Permalink
Added strike support to markdown (#1563)
Browse files Browse the repository at this point in the history
This PR adds support for the strike operator in [both forms][1].

It does not include actual styling for the strike operator as it
makes the ~ character really hard to read.

[1]: https://webapps.stackexchange.com/questions/14986/strikethrough-with-github-markdown/103691#103691
  • Loading branch information
RunDevelopment authored and mAAdhaTTah committed Nov 28, 2018
1 parent 7155e60 commit 9d2fddc
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 3 deletions.
21 changes: 20 additions & 1 deletion components/prism-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Prism.languages.insertBefore('markdown', 'prolog', {
// Allow only one line break
pattern: /(^|[^\\])(\*\*|__)(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,
lookbehind: true,
greedy: true,
inside: {
'punctuation': /^\*\*|^__|\*\*$|__$/
}
Expand All @@ -94,10 +95,23 @@ Prism.languages.insertBefore('markdown', 'prolog', {
// Allow only one line break
pattern: /(^|[^\\])([*_])(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,
lookbehind: true,
greedy: true,
inside: {
'punctuation': /^[*_]|[*_]$/
}
},
'strike': {
// ~~strike through~~
// ~strike~

// Allow only one line break
pattern: /(^|[^\\])(~~?)(?:(?:\r?\n|\r)(?!\r?\n|\r)|.)+?\2/,
lookbehind: true,
greedy: true,
inside: {
'punctuation': /^~~?|~~?$/
}
},
'url': {
// [example](http://example.com "Optional title")
// [example] [id]
Expand All @@ -116,5 +130,10 @@ Prism.languages.insertBefore('markdown', 'prolog', {

Prism.languages.markdown['bold'].inside['url'] = Prism.languages.markdown['url'];
Prism.languages.markdown['italic'].inside['url'] = Prism.languages.markdown['url'];
Prism.languages.markdown['strike'].inside['url'] = Prism.languages.markdown['url'];
Prism.languages.markdown['bold'].inside['italic'] = Prism.languages.markdown['italic'];
Prism.languages.markdown['italic'].inside['bold'] = Prism.languages.markdown['bold'];
Prism.languages.markdown['bold'].inside['strike'] = Prism.languages.markdown['strike'];
Prism.languages.markdown['italic'].inside['bold'] = Prism.languages.markdown['bold'];
Prism.languages.markdown['italic'].inside['strike'] = Prism.languages.markdown['strike'];
Prism.languages.markdown['strike'].inside['bold'] = Prism.languages.markdown['bold'];
Prism.languages.markdown['strike'].inside['italic'] = Prism.languages.markdown['italic'];
2 changes: 1 addition & 1 deletion components/prism-markdown.min.js

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

14 changes: 13 additions & 1 deletion tests/languages/markdown/bold_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ bar__

__foo*bar*baz__
__foo_bar_baz__
__foo~bar~baz__
__foo[bar](baz)__

----------------------------------------------------
Expand Down Expand Up @@ -55,6 +56,17 @@ __foo[bar](baz)__
"baz",
["punctuation", "__"]
]],
["bold", [
["punctuation", "__"],
"foo",
["strike", [
["punctuation", "~"],
"bar",
["punctuation", "~"]
]],
"baz",
["punctuation", "__"]
]],
["bold", [
["punctuation", "__"],
"foo",
Expand All @@ -67,4 +79,4 @@ __foo[bar](baz)__

----------------------------------------------------

Checks for bold. Also tests for inclusion of italic and url.
Checks for bold. Also tests for inclusion of italic, strike, and url.
70 changes: 70 additions & 0 deletions tests/languages/markdown/strike_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
~~foobar~~
~~foo
bar~~
~foobar~
~foo
bar~

~foo*bar*baz~
~foo__bar__baz~
~foo[bar](baz)~

----------------------------------------------------

[
["strike", [
["punctuation", "~~"],
"foobar",
["punctuation", "~~"]
]],
["strike", [
["punctuation", "~~"],
"foo\r\nbar",
["punctuation", "~~"]
]],
["strike", [
["punctuation", "~"],
"foobar",
["punctuation", "~"]
]],
["strike", [
["punctuation", "~"],
"foo\r\nbar",
["punctuation", "~"]
]],

["strike", [
["punctuation", "~"],
"foo",
["italic", [
["punctuation", "*"],
"bar",
["punctuation", "*"]
]],
"baz",
["punctuation", "~"]
]],
["strike", [
["punctuation", "~"],
"foo",
["bold", [
["punctuation", "__"],
"bar",
["punctuation", "__"]
]],
"baz",
["punctuation", "~"]
]],
["strike", [
["punctuation", "~"],
"foo",
["url", [
"[bar](baz)"
]],
["punctuation", "~"]
]]
]

----------------------------------------------------

Checks for strike. Also tests for inclusion of bold, italic, and url.

0 comments on commit 9d2fddc

Please sign in to comment.