Skip to content

Commit

Permalink
refactor: escaped characters within tag attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
tivie committed Oct 24, 2017
1 parent e862e24 commit 32800a1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 13 deletions.
9 changes: 4 additions & 5 deletions dist/showdown.js

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

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions src/subParsers/escapeSpecialCharsWithinTagAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ showdown.subParser('escapeSpecialCharsWithinTagAttributes', function (text, opti
text = globals.converter._dispatch('escapeSpecialCharsWithinTagAttributes.before', text, options, globals);

// Build a regex to find HTML tags.
var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>)/gi,
// due to catastrophic backtrace we split the old regex into two, one for tags and one for comments
regexComments = /<!(--(?:|(?:[^>-]|-[^>])(?:[^-]|-[^-])*)--)>/gi;
var tags = /<\/?[a-z\d_:-]+(?:[\s]+[\s\S]+?)?>/gi,
comments = /<!(--(?:(?:[^>-]|-[^>])(?:[^-]|-[^-])*)--)>/gi;

text = text.replace(regex, function (wholeMatch) {
text = text.replace(tags, function (wholeMatch) {
return wholeMatch
.replace(/(.)<\/?code>(?=.)/g, '$1`')
.replace(/([\\`*_~=|])/g, showdown.helper.escapeCharactersCallback);
});

text = text.replace(regexComments, function (wholeMatch) {
text = text.replace(comments, function (wholeMatch) {
return wholeMatch
.replace(/([\\`*_~=|])/g, showdown.helper.escapeCharactersCallback);
});
Expand Down

0 comments on commit 32800a1

Please sign in to comment.