Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions dist/htmlminifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@
while (index > 0 && !/^<\//.test(buffer[index])) {
index--;
}
buffer.length = index;
buffer.length = Math.max(0, index);
}

new HTMLParser(value, {
Expand Down Expand Up @@ -1415,20 +1415,8 @@
if (lowerTag === 'svg') {
options = optionsStack.pop();
}

tag = options.caseSensitive ? tag : lowerTag;

if (options.removeOptionalTags) {
// </html> or </body> may be omitted if not followed by comment
// </head> may be omitted if not followed by space or comment
// </p> may be omitted if no more content in non-</a> parent
// except for </dt> or </thead>, end tags may be omitted if no more content in parent element
if (optionalEndTag && optionalEndTag !== 'dt' && optionalEndTag !== 'thead' && (optionalEndTag !== 'p' || !pInlineTags(tag))) {
removeEndTag();
}
optionalEndTag = optionalEndTags(tag) ? tag : '';
}

// check if current tag is in a whitespace stack
if (options.collapseWhitespace) {
if (stackNoTrimWhitespace.length) {
Expand Down Expand Up @@ -1461,6 +1449,23 @@
currentTag = '';
isElementEmpty = currentChars === '';
}

if (options.removeOptionalTags) {
// <html>, <head> or <body> may be omitted if the element is empty
if (isElementEmpty && topLevelTags(optionalStartTag)) {
removeStartTag();
}
optionalStartTag = '';
// </html> or </body> may be omitted if not followed by comment
// </head> may be omitted if not followed by space or comment
// </p> may be omitted if no more content in non-</a> parent
// except for </dt> or </thead>, end tags may be omitted if no more content in parent element
if (optionalEndTag && optionalEndTag !== 'dt' && optionalEndTag !== 'thead' && (optionalEndTag !== 'p' || !pInlineTags(tag))) {
removeEndTag();
}
optionalEndTag = optionalEndTags(tag) ? tag : '';
}

if (options.removeEmptyElements && isElementEmpty && canRemoveElement(tag, attrs)) {
// remove last "element" from buffer
removeStartTag();
Expand Down
Loading