Applied rustfmt
This commit is contained in:
parent
ab65b44f0d
commit
de383c94b1
2 changed files with 40 additions and 43 deletions
15
src/html.rs
15
src/html.rs
|
@ -7,9 +7,9 @@ use html5ever::tree_builder::{Attribute, TreeSink};
|
|||
use html5ever::{local_name, namespace_url, ns};
|
||||
use http::retrieve_asset;
|
||||
use js::attr_is_event_handler;
|
||||
use std::fmt::Write as OtherWrite;
|
||||
use std::collections::HashMap;
|
||||
use std::default::Default;
|
||||
use std::fmt::Write as OtherWrite;
|
||||
use utils::{data_to_dataurl, is_valid_url, resolve_css_imports, resolve_url, url_has_protocol};
|
||||
|
||||
lazy_static! {
|
||||
|
@ -139,7 +139,6 @@ pub fn walk_and_embed_assets(
|
|||
opt_silent,
|
||||
opt_insecure,
|
||||
) {
|
||||
|
||||
// On successful retrieval, traverse CSS
|
||||
Ok((css_data, _)) => resolve_css_imports(
|
||||
cache,
|
||||
|
@ -153,14 +152,11 @@ pub fn walk_and_embed_assets(
|
|||
|
||||
// If a network error occured, warn
|
||||
Err(e) => {
|
||||
eprintln!(
|
||||
"Warning: {}",
|
||||
e,
|
||||
);
|
||||
eprintln!("Warning: {}", e,);
|
||||
|
||||
//If failed to resolve, replace with absolute URL
|
||||
href_full_url
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
attr.value.clear();
|
||||
|
@ -299,7 +295,7 @@ pub fn walk_and_embed_assets(
|
|||
node.children.borrow_mut().clear();
|
||||
} else {
|
||||
for node in node.children.borrow_mut().iter_mut() {
|
||||
if let NodeData::Text{ref contents} = node.data {
|
||||
if let NodeData::Text { ref contents } = node.data {
|
||||
let mut tendril = contents.borrow_mut();
|
||||
let replacement = resolve_css_imports(
|
||||
cache,
|
||||
|
@ -311,7 +307,8 @@ pub fn walk_and_embed_assets(
|
|||
opt_insecure,
|
||||
);
|
||||
tendril.clear();
|
||||
tendril.write_str(&replacement)
|
||||
tendril
|
||||
.write_str(&replacement)
|
||||
.expect("Failed to update DOM");
|
||||
}
|
||||
}
|
||||
|
|
68
src/utils.rs
68
src/utils.rs
|
@ -3,8 +3,8 @@ extern crate base64;
|
|||
use self::base64::encode;
|
||||
use http::retrieve_asset;
|
||||
use regex::Regex;
|
||||
use url::{ParseError, Url};
|
||||
use std::collections::HashMap;
|
||||
use url::{ParseError, Url};
|
||||
|
||||
lazy_static! {
|
||||
static ref HAS_PROTOCOL: Regex = Regex::new(r"^[a-z0-9]+:").unwrap();
|
||||
|
@ -88,7 +88,8 @@ pub fn resolve_css_imports(
|
|||
opt_insecure: bool,
|
||||
) -> String {
|
||||
let mut resolved_css = String::from(css_string);
|
||||
let re = Regex::new(r###"(?P<import>@import )?url\((?P<to_repl>"?(?P<url>[^"]+)"?)\)"###).unwrap();
|
||||
let re =
|
||||
Regex::new(r###"(?P<import>@import )?url\((?P<to_repl>"?(?P<url>[^"]+)"?)\)"###).unwrap();
|
||||
|
||||
for link in re.captures_iter(&css_string) {
|
||||
let target_link = link.name("url").unwrap().as_str();
|
||||
|
@ -101,43 +102,42 @@ pub fn resolve_css_imports(
|
|||
|
||||
// Download the asset. If it's more CSS, resolve that too
|
||||
let content = match link.name("import") {
|
||||
|
||||
// The link is an @import link
|
||||
Some(_) => retrieve_asset(
|
||||
cache,
|
||||
&embedded_url,
|
||||
false, // Formating as data URL will be done later
|
||||
"text/css", // Expect CSS
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
opt_insecure,
|
||||
)
|
||||
.map(|(content, _)| resolve_css_imports(
|
||||
cache,
|
||||
&content,
|
||||
true, //NOW, convert to data URL
|
||||
&embedded_url,
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
opt_insecure,
|
||||
)),
|
||||
cache,
|
||||
&embedded_url,
|
||||
false, // Formating as data URL will be done later
|
||||
"text/css", // Expect CSS
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
opt_insecure,
|
||||
)
|
||||
.map(|(content, _)| {
|
||||
resolve_css_imports(
|
||||
cache,
|
||||
&content,
|
||||
true, //NOW, convert to data URL
|
||||
&embedded_url,
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
opt_insecure,
|
||||
)
|
||||
}),
|
||||
|
||||
// The link is some other, non-@import link
|
||||
None => retrieve_asset(
|
||||
cache,
|
||||
&embedded_url,
|
||||
true, // Format as data URL
|
||||
"", // Unknown MIME type
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
opt_insecure,
|
||||
).map(|(a, _)| a),
|
||||
|
||||
}.unwrap_or_else(|e| {
|
||||
eprintln!(
|
||||
"Warning: {}",
|
||||
e,
|
||||
);
|
||||
cache,
|
||||
&embedded_url,
|
||||
true, // Format as data URL
|
||||
"", // Unknown MIME type
|
||||
opt_user_agent,
|
||||
opt_silent,
|
||||
opt_insecure,
|
||||
)
|
||||
.map(|(a, _)| a),
|
||||
}
|
||||
.unwrap_or_else(|e| {
|
||||
eprintln!("Warning: {}", e,);
|
||||
|
||||
//If failed to resolve, replace with absolute URL
|
||||
embedded_url
|
||||
|
|
Loading…
Add table
Reference in a new issue