mirror of
https://github.com/showdownjs/showdown.git
synced 2024-03-22 13:30:55 +08:00
fix(hashCodeTags): escape code tags
Previously, `<code>` tags were not escaped. This was counter intuitive since ´<pre><code>` tags were being escaped. Now both pre code and code are escaped. Closes #339
This commit is contained in:
parent
7f43b79b33
commit
41cb3f6b7f
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.
18
src/subParsers/hashCodeTags.js
Normal file
18
src/subParsers/hashCodeTags.js
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/**
|
||||||
|
* Hash and escape <code> elements that should not be parsed as markdown
|
||||||
|
*/
|
||||||
|
showdown.subParser('hashCodeTags', function (text, options, globals) {
|
||||||
|
'use strict';
|
||||||
|
text = globals.converter._dispatch('hashCodeTags.before', text, options, globals);
|
||||||
|
|
||||||
|
var repFunc = function (wholeMatch, match, left, right) {
|
||||||
|
var codeblock = left + showdown.subParser('encodeCode')(match, options, globals) + right;
|
||||||
|
return '¨C' + (globals.gHtmlSpans.push(codeblock) - 1) + 'C';
|
||||||
|
};
|
||||||
|
|
||||||
|
// Hash naked <code>
|
||||||
|
text = showdown.helper.replaceRecursiveRegExp(text, repFunc, '<code\\b[^>]*>', '</code>', 'gim');
|
||||||
|
|
||||||
|
text = globals.converter._dispatch('hashCodeTags.after', text, options, globals);
|
||||||
|
return text;
|
||||||
|
});
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Hash span elements that should not be parsed as markdown
|
* Hash and escape <pre><code> elements that should not be parsed as markdown
|
||||||
*/
|
*/
|
||||||
showdown.subParser('hashPreCodeTags', function (text, options, globals) {
|
showdown.subParser('hashPreCodeTags', function (text, options, globals) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
@ -17,15 +17,3 @@ showdown.subParser('hashPreCodeTags', function (text, options, globals) {
|
||||||
text = globals.converter._dispatch('hashPreCodeTags.after', text, options, globals);
|
text = globals.converter._dispatch('hashPreCodeTags.after', text, options, globals);
|
||||||
return text;
|
return text;
|
||||||
});
|
});
|
||||||
|
|
||||||
showdown.subParser('hashCodeTags', function (text, options, globals) {
|
|
||||||
'use strict';
|
|
||||||
text = globals.converter._dispatch('hashCodeTags.before', text, options, globals);
|
|
||||||
// Hash naked <code>
|
|
||||||
var matches = showdown.helper.matchRecursiveRegExp(text, '<code\\b[^>]*>', '</code>', 'gi');
|
|
||||||
for (var i = 0; i < matches.length; ++i) {
|
|
||||||
text = text.replace(matches[i][0], '¨C' + (globals.gHtmlSpans.push(matches[i][0]) - 1) + 'C');
|
|
||||||
}
|
|
||||||
text = globals.converter._dispatch('hashCodeTags.after', text, options, globals);
|
|
||||||
return text;
|
|
||||||
});
|
|
||||||
|
|
4
test/cases/encodeHTMLCodeTags.html
Normal file
4
test/cases/encodeHTMLCodeTags.html
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<p>this is code <code>some <span>text</span></code> yeah!</p>
|
||||||
|
<pre><code>
|
||||||
|
<div>foo</div>
|
||||||
|
</code></pre>
|
5
test/cases/encodeHTMLCodeTags.md
Normal file
5
test/cases/encodeHTMLCodeTags.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
this is code <code>some <span>text</span></code> yeah!
|
||||||
|
|
||||||
|
<pre><code>
|
||||||
|
<div>foo</div>
|
||||||
|
</code></pre>
|
|
@ -1,5 +1,5 @@
|
||||||
<p><code>some **code** yeah</code></p>
|
<p><code>some **code** yeah</code></p>
|
||||||
<p>some <code>inline **code** block</code></p>
|
<p>some <code>inline **code** block</code></p>
|
||||||
<p><code>some inline **code**</code> block</p>
|
<p><code>some inline **code**</code> block</p>
|
||||||
<p>yo dawg <code start="true">some <code start="false">code</code> inception</code></p>
|
<p>yo dawg <code start="true">some <code start="false">code</code> inception</code></p>
|
||||||
<div>some **div** yeah</div>
|
<div>some **div** yeah</div>
|
Loading…
Reference in New Issue
Block a user