From bd7d999ca87954b44a4c398986866288d3ff1080 Mon Sep 17 00:00:00 2001 From: Ze Yu Date: Sat, 11 Apr 2020 17:04:23 +0800 Subject: [PATCH] Allow variable tags to contain malformed xml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../markdown-it/markdown-it-escape-special-tags.js | 2 +- src/lib/markbind/src/patches/htmlparser2.js | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib/markbind/src/lib/markdown-it/markdown-it-escape-special-tags.js b/src/lib/markbind/src/lib/markdown-it/markdown-it-escape-special-tags.js index d0b31c2a9b..9b82e4d7d5 100644 --- a/src/lib/markbind/src/lib/markdown-it/markdown-it-escape-special-tags.js +++ b/src/lib/markbind/src/lib/markdown-it/markdown-it-escape-special-tags.js @@ -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'); diff --git a/src/lib/markbind/src/patches/htmlparser2.js b/src/lib/markbind/src/patches/htmlparser2.js index 53ba30a04d..526e3b7db2 100644 --- a/src/lib/markbind/src/patches/htmlparser2.js +++ b/src/lib/markbind/src/patches/htmlparser2.js @@ -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"; } @@ -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, @@ -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;