-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(literalMidWordUnderscores): add support for GFM literal midword …
…underscores Github Flavored Markdown does not parse underscores in the middle of a word as emphasis/bold. This commit adds this feature to showdown through an option called "literalMidWordUnderscores". Related to #164
- Loading branch information
Showing
11 changed files
with
78 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,19 @@ | ||
showdown.subParser('italicsAndBold', function (text) { | ||
showdown.subParser('italicsAndBold', function (text, options) { | ||
'use strict'; | ||
// <strong> must go first: | ||
text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g, '<strong>$2</strong>'); | ||
|
||
text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, '<em>$2</em>'); | ||
if (options.literalMidWordUnderscores) { | ||
//underscores | ||
// Since we are consuming a \s character, we need to add it | ||
text = text.replace(/(\s)__(?=\S)([^]+?)__(?=\s)/g, '$1<strong>$2</strong>'); | ||
text = text.replace(/(\s)_(?=\S)([^]+?)_(?=\s)/g, '$1<em>$2</em>'); | ||
//asterisks | ||
text = text.replace(/\*\*(?=\S)([^]+?)\*\*/g, '<strong>$1</strong>'); | ||
text = text.replace(/\*(?=\S)([^]+?)\*/g, '<em>$1</em>'); | ||
|
||
} else { | ||
// <strong> must go first: | ||
text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g, '<strong>$2</strong>'); | ||
text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g, '<em>$2</em>'); | ||
} | ||
return text; | ||
}); |
11 changes: 11 additions & 0 deletions
11
test/features/#164.2.disallow_underscore_emphasis_mid_word.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<p>this is a sentence_with_mid underscores</p> | ||
|
||
<p>this is a sentence with just_one underscore</p> | ||
|
||
<p>this <em>should be parsed</em> as emphasis</p> | ||
|
||
<p>this is double__underscore__mid word</p> | ||
|
||
<p>this has just__one double underscore</p> | ||
|
||
<p>this <strong>should be parsed</strong> as bold</p> |
11 changes: 11 additions & 0 deletions
11
test/features/#164.2.disallow_underscore_emphasis_mid_word.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
this is a sentence_with_mid underscores | ||
|
||
this is a sentence with just_one underscore | ||
|
||
this _should be parsed_ as emphasis | ||
|
||
this is double__underscore__mid word | ||
|
||
this has just__one double underscore | ||
|
||
this __should be parsed__ as bold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters