Update minify and respect HTML spec
This commit is contained in:
parent
17f3fe2bda
commit
85f68f87cc
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -1404,9 +1404,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "minify-html"
|
name = "minify-html"
|
||||||
version = "0.4.11"
|
version = "0.5.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ee59033f9253bab9ec605e58b6a9f9ac22548346cbc88927194a7f56527b541b"
|
checksum = "4724a59fe4c7e7a6a0389cf151027b11a29ee0a4f838e7871533896d68910907"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick",
|
"aho-corasick",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
|
|
|
@ -14,7 +14,7 @@ serde = { version = "1.0", features = ["derive"] }
|
||||||
slug = "0.1"
|
slug = "0.1"
|
||||||
percent-encoding = "2"
|
percent-encoding = "2"
|
||||||
filetime = "0.2.12"
|
filetime = "0.2.12"
|
||||||
minify-html = "0.4.2"
|
minify-html = "0.5"
|
||||||
|
|
||||||
errors = { path = "../errors" }
|
errors = { path = "../errors" }
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,16 @@
|
||||||
use errors::{bail, Result};
|
use errors::{bail, Result};
|
||||||
use minify_html::{with_friendly_error, Cfg};
|
use minify_html::{minify, Cfg};
|
||||||
|
|
||||||
pub fn html(html: String) -> Result<String> {
|
pub fn html(html: String) -> Result<String> {
|
||||||
let cfg = &Cfg { minify_js: false, minify_css: false };
|
let mut cfg = Cfg::new();
|
||||||
let mut input_bytes = html.as_bytes().to_vec();
|
cfg.ensure_spec_compliant_unquoted_attribute_values = true;
|
||||||
|
cfg.keep_spaces_between_attributes = true;
|
||||||
|
cfg.keep_html_and_head_opening_tags = true;
|
||||||
|
|
||||||
match with_friendly_error(&mut input_bytes, cfg) {
|
let minified = minify(html.as_bytes(), &cfg);
|
||||||
Ok(len) => match std::str::from_utf8(&input_bytes[..len]) {
|
match std::str::from_utf8(&minified) {
|
||||||
Ok(result) => Ok(result.to_string()),
|
Ok(result) => Ok(result.to_string()),
|
||||||
Err(err) => bail!("Failed to convert bytes to string : {}", err),
|
Err(err) => bail!("Failed to convert bytes to string : {}", err),
|
||||||
},
|
|
||||||
Err(minify_error) => {
|
|
||||||
bail!(
|
|
||||||
"Failed to truncate html at character {}: {} \n {}",
|
|
||||||
minify_error.position,
|
|
||||||
minify_error.message,
|
|
||||||
minify_error.code_context
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue