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