fix(html/minifier): Small fix (#5079)

This commit is contained in:
Alexander Akait 2022-07-03 07:14:51 +03:00 committed by GitHub
parent 279d4a39c1
commit 5ac5ae200c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 65 additions and 7 deletions

View File

@ -1227,11 +1227,6 @@ impl Minifier {
result
});
// Remove all leading and trailing whitespaces for the `body` element
if namespace == Namespace::HTML && tag_name == "body" {
self.remove_leading_and_trailing_whitespaces(children);
}
}
fn get_attribute_value(&self, attributes: &Vec<Attribute>, name: &str) -> Option<JsWord> {
@ -1714,6 +1709,14 @@ impl VisitMut for Minifier {
n.visit_mut_children_with(self);
// Remove all leading and trailing whitespaces for the `body` element
if n.namespace == Namespace::HTML
&& &*n.tag_name == "body"
&& self.need_collapse_whitespace()
{
self.remove_leading_and_trailing_whitespaces(&mut n.children);
}
if self.need_collapse_whitespace() {
self.descendant_of_pre = old_descendant_of_pre;
}

View File

@ -1,6 +1,7 @@
<!doctype html><html lang=en><head>
<title>Document</title>
</head>
<body>
<div> test </div>
<div>
@ -271,4 +272,6 @@
<div> text </div>
<span> text </span>
<span> text </span>
<span> text </span>

View File

@ -0,0 +1,3 @@
{
"collapseWhitespaces": "smart"
}

View File

@ -0,0 +1,3 @@
<!doctype html>
<html lang="en">
<div> <a href="#"> <span> <b> foo </b> z <i> bar </i> </span> </a> </div>

View File

@ -0,0 +1 @@
<!doctype html><html lang=en><div><a href=#><span><b>foo</b>z <i>bar</i></span></a></div>

View File

@ -0,0 +1,3 @@
{
"collapseWhitespaces": "smart"
}

View File

@ -0,0 +1,3 @@
<!doctype html>
<html lang="en">
<span> <!-- test --> text <!-- test --></span>

View File

@ -0,0 +1 @@
<!doctype html><html lang=en><span>text</span>

View File

@ -0,0 +1,3 @@
{
"collapseWhitespaces": "smart"
}

View File

@ -0,0 +1,3 @@
<!doctype html>
<html lang="en">
<div><span> <!-- test --> text <!-- test --></span></div>

View File

@ -0,0 +1 @@
<!doctype html><html lang=en><div><span>text</span></div>

View File

@ -0,0 +1,3 @@
{
"collapseWhitespaces": "smart"
}

View File

@ -0,0 +1,3 @@
<!doctype html>
<html lang="en">
<span> <!-- test --> text <!-- test --></span> <span> <!-- test --> text <!-- test --></span>

View File

@ -0,0 +1 @@
<!doctype html><html lang=en><span>text</span> <span>text</span>

View File

@ -0,0 +1,3 @@
{
"collapseWhitespaces": "smart"
}

View File

@ -0,0 +1,2 @@
<!doctype html>
<svg> <linearGradient id=gradient /> </svg>

View File

@ -0,0 +1 @@
<!doctype html><svg><linearGradient id=gradient /></svg>

View File

@ -0,0 +1,3 @@
{
"collapseWhitespaces": "smart"
}

View File

@ -0,0 +1,2 @@
<!doctype html>
<span>a</span> <svg> <linearGradient id=gradient /> </svg>

View File

@ -0,0 +1 @@
<!doctype html><span>a</span> <svg><linearGradient id=gradient /></svg>

View File

@ -0,0 +1,3 @@
{
"collapseWhitespaces": "smart"
}

View File

@ -0,0 +1,2 @@
<!doctype html>
<svg> <linearGradient id=gradient /> </svg> <span>a</span>

View File

@ -0,0 +1 @@
<!doctype html><svg><linearGradient id=gradient /></svg><span>a</span>

View File

@ -0,0 +1,3 @@
{
"collapseWhitespaces": "smart"
}

View File

@ -0,0 +1,2 @@
<!doctype html>
<span>a</span> <svg> <linearGradient id=gradient /> </svg> <span>a</span>

View File

@ -0,0 +1 @@
<!doctype html><span>a</span> <svg><linearGradient id=gradient /> </svg><span>a</span>

View File

@ -1 +1 @@
<!doctype html><html lang=en><meta charset=UTF-8><meta name=viewport content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title><div><span>test</span><noscript><a href=#>External Link</a></noscript></div><div><span>test</span><noscript> <a href=#>External Link</a></noscript></div>
<!doctype html><html lang=en><meta charset=UTF-8><meta name=viewport content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0"><meta http-equiv=X-UA-Compatible content="ie=edge"><title>Document</title><div><span>test</span><noscript><a href=#>External Link</a></noscript></div><div><span>test</span><noscript><a href=#>External Link</a></noscript></div>