From de383c94b11e1689ef2f765bd8a18f15b1236307 Mon Sep 17 00:00:00 2001 From: Emi Simpson Date: Thu, 5 Dec 2019 20:41:43 -0500 Subject: [PATCH] Applied rustfmt --- src/html.rs | 15 +++++------- src/utils.rs | 68 ++++++++++++++++++++++++++-------------------------- 2 files changed, 40 insertions(+), 43 deletions(-) diff --git a/src/html.rs b/src/html.rs index 2f7fb8f..00914ed 100644 --- a/src/html.rs +++ b/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"); } } diff --git a/src/utils.rs b/src/utils.rs index e92edb8..2fcdfea 100644 --- a/src/utils.rs +++ b/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 )?url\((?P"?(?P[^"]+)"?)\)"###).unwrap(); + let re = + Regex::new(r###"(?P@import )?url\((?P"?(?P[^"]+)"?)\)"###).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