Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@ function escape_plugin(md, tagsToIgnore) {
const specialTagsRegex = Array.from(tagsToIgnore)
.concat(['script|pre|style|variable'])
.join('|');
const startingSpecialTagRegex = new RegExp(`^<(${specialTagsRegex})(?=(\\s|>|$))`, 'i');

// attr_name, unquoted ... attribute patterns adapted from markdown-it/lib/common/html_re
// Construct self-closing negative lookahead for special tags,
// because if matched, the endingSpecialTagRegex will roll down to find a non-existent closing tag
const attr_name = '[a-zA-Z_:][a-zA-Z0-9:._-]*';
const unquoted = '[^"\'=<>`\\x00-\\x20]+';
const single_quoted = "'[^']*'";
const double_quoted = '"[^"]*"';
const attr_value = '(?:' + unquoted + '|' + single_quoted + '|' + double_quoted + ')';
const attribute = '(?:\\s+' + attr_name + '(?:\\s*=\\s*' + attr_value + ')?)';
const selfClosingNegativeLookahead = `(?!${attribute}*\\s*\/>)`;

const startingSpecialTagRegex = new RegExp(
`^<(${specialTagsRegex})${selfClosingNegativeLookahead}(?=(\\s|>|$))`, 'i');
const endingSpecialTagRegex = new RegExp(`<\\/(${specialTagsRegex})>`, 'i');

const HTML_SEQUENCES = [
Expand Down