-
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(hashHTMLSpans): Add support for hashing span elements
This feature enables hashing span elements that should not be touched by showdown. For instance, `<code>` tags in markdown source should not be parsed by showdown, so the text inside them remains unchanged. This is made possible by a new exciting internal feature, matchRecursiveRegExp. Closes #196, Closes #175, Partially reverts 5f043ca
- Loading branch information
Showing
10 changed files
with
222 additions
and
7 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
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,26 @@ | ||
/** | ||
* Hash span elements that should not be parsed as markdown | ||
*/ | ||
showdown.subParser('hashHTMLSpans', function (text, config, globals) { | ||
'use strict'; | ||
|
||
var matches = showdown.helper.matchRecursiveRegExp(text, '<code\\b[^>]*>', '</code>', 'gi'); | ||
|
||
for (var i = 0; i < matches.length; ++i) { | ||
text = text.replace(matches[i][0], '~L' + (globals.gHtmlSpans.push(matches[i][0]) - 1) + 'L'); | ||
} | ||
return text; | ||
}); | ||
|
||
/** | ||
* Unhash HTML spans | ||
*/ | ||
showdown.subParser('unhashHTMLSpans', function (text, config, globals) { | ||
'use strict'; | ||
|
||
for (var i = 0; i < globals.gHtmlSpans.length; ++i) { | ||
text = text.replace('~L' + i + 'L', globals.gHtmlSpans[i]); | ||
} | ||
|
||
return text; | ||
}); |
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,9 @@ | ||
<p><code>some **code** yeah</code></p> | ||
|
||
<p>some <code>inline **code** block</code></p> | ||
|
||
<p><code>some inline **code**</code> block</p> | ||
|
||
<p>yo dawg <code start="true">some <code start="false">code</code> inception</code></p> | ||
|
||
<div>some **div** yeah</div> |
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,9 @@ | ||
<code>some **code** yeah</code> | ||
|
||
some <code>inline **code** block</code> | ||
|
||
<code>some inline **code**</code> block | ||
|
||
yo dawg <code start="true">some <code start="false">code</code> inception</code> | ||
|
||
<div>some **div** yeah</div> |