Skip to content

Commit

Permalink
fix(subParsers/codeSpans): Fix issue with code html tags not being co…
Browse files Browse the repository at this point in the history
…rrectly escaped
  • Loading branch information
tivie committed Jul 14, 2015
1 parent 220b85d commit 5f043ca
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/subParsers/codeSpans.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
showdown.subParser('codeSpans', function (text) {
'use strict';

//special case -> literal html code tag
text = text.replace(/(<code[^><]*?>)([^]*?)<\/code>/g, function (wholeMatch, tag, c) {
c = c.replace(/^([ \t]*)/g, ''); // leading whitespace
c = c.replace(/[ \t]*$/g, ''); // trailing whitespace
c = showdown.subParser('encodeCode')(c);
return tag + c + '</code>';
});

/*
text = text.replace(/
(^|[^\\]) // Character before opening ` can't be a backslash
Expand All @@ -38,15 +46,14 @@ showdown.subParser('codeSpans', function (text) {
(?!`)
/gm, function(){...});
*/

text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm, function (wholeMatch, m1, m2, m3) {
var c = m3;
c = c.replace(/^([ \t]*)/g, ''); // leading whitespace
c = c.replace(/[ \t]*$/g, ''); // trailing whitespace
c = showdown.subParser('encodeCode')(c);
return m1 + '<code>' + c + '</code>';
text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
function (wholeMatch, m1, m2, m3) {
var c = m3;
c = c.replace(/^([ \t]*)/g, ''); // leading whitespace
c = c.replace(/[ \t]*$/g, ''); // trailing whitespace
c = showdown.subParser('encodeCode')(c);
return m1 + '<code>' + c + '</code>';
});

return text;

});

0 comments on commit 5f043ca

Please sign in to comment.