mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-02 08:32:41 +00:00
Add voidTags whitelist and functionality
This commit is contained in:
@@ -511,6 +511,12 @@ const tagRegex = new RegExp(`(${
|
||||
return `\\<${type}\\b|\\</${type}>`;
|
||||
}).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 === `</${type}>`){
|
||||
// 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,
|
||||
|
||||
Reference in New Issue
Block a user