diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 1b6a7f3ce..06eb3833b 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -511,6 +511,12 @@ const tagRegex = new RegExp(`(${ return `\\<${type}\\b|\\`; }).join('|')})`, 'g'); +// Special "void" tags that can be self-closed but don't need to be. +const voidTags = new Set([ + 'area', 'base', 'br', 'col', 'command', 'hr', 'img', + 'input', 'keygen', 'link', 'meta', 'param', 'source' +]); + const processStyleTags = (string)=>{ //split tags up. quotes can only occur right after colons. //TODO: can we simplify to just split on commas? @@ -551,6 +557,13 @@ module.exports = { }); } if(match === ``){ + // Closing tag: Check we expect it to be closed. + // The accumulator may contain a sequence of voidable opening tags, + // over which we skip before checking validity of the close. + while (acc.length && voidTags.has(_.last(acc).type) && _.last(acc).type != type) { + acc.pop(); + } + // Now check that what remains in the accumulator is valid. if(!acc.length){ errors.push({ line : lineNumber,