Skip to content

Commit

Permalink
Allow variable tags to contain malformed xml (#1193)
Browse files Browse the repository at this point in the history
With the special tags patch, variables are able to contain custom
content possibly containing malformed xml.

Let’s add variable to the list of special tags to do so.
  • Loading branch information
ang-zeyu committed Apr 12, 2020
1 parent 705949a commit bdc4b0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function escape_plugin(md, tagsToIgnore) {
const HTML_OPEN_CLOSE_TAG_RE = require('markdown-it/lib/common/html_re').HTML_OPEN_CLOSE_TAG_RE;

const specialTagsRegex = Array.from(tagsToIgnore)
.concat(['script|pre|style'])
.concat(['script|pre|style|variable'])
.join('|');
const startingSpecialTagRegex = new RegExp(`^<(${specialTagsRegex})(?=(\\s|>|$))`, 'i');
const endingSpecialTagRegex = new RegExp(`<\\/(${specialTagsRegex})>`, 'i');
Expand Down
13 changes: 8 additions & 5 deletions src/lib/markbind/src/patches/htmlparser2.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ var i = 0,
NO_MATCH = -2,
HAS_MATCHED = -3;

const DEFAULT_SPECIAL_TAGS = [
'script',
'style',
'variable',
];

function whitespace(c) {
return c === " " || c === "\n" || c === "\t" || c === "\f" || c === "\r";
}
Expand Down Expand Up @@ -149,10 +155,7 @@ Tokenizer.prototype._stateText = function(c) {
};


Tokenizer.prototype.specialTagNames = [
'script',
'style',
];
Tokenizer.prototype.specialTagNames = [...DEFAULT_SPECIAL_TAGS];

/**
* Checks whether the token matches one of the first characters of the special tags,
Expand Down Expand Up @@ -485,7 +488,7 @@ Tokenizer.prototype._parse = function(){
* Injects the tagsToIgnore into the Tokenizer's specialTagNames.
*/
function injectIgnoreTags(tagsToIgnore) {
Tokenizer.prototype.specialTagNames = ['script', 'style', ...tagsToIgnore];
Tokenizer.prototype.specialTagNames = [...DEFAULT_SPECIAL_TAGS, ...tagsToIgnore];
}

module.exports = injectIgnoreTags;

0 comments on commit bdc4b0c

Please sign in to comment.