Gramatical and stylistic fixes

This commit is contained in:
Emi Simpson 2019-12-09 12:41:21 -05:00
parent 028beb821c
commit 614af44c92
No known key found for this signature in database
GPG key ID: 68FAB2E2E6DFC98B
2 changed files with 17 additions and 23 deletions

View file

@ -9,7 +9,6 @@ use http::retrieve_asset;
use js::attr_is_event_handler; use js::attr_is_event_handler;
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! {
@ -155,7 +154,7 @@ pub fn walk_and_embed_assets(
Err(e) => { Err(e) => {
eprintln!("Warning: {}", e,); eprintln!("Warning: {}", e,);
//If failed to resolve, replace with absolute URL // If failed to resolve, replace with absolute URL
href_full_url href_full_url
} }
}; };
@ -309,9 +308,7 @@ pub fn walk_and_embed_assets(
opt_insecure, opt_insecure,
); );
tendril.clear(); tendril.clear();
tendril tendril.push_slice(&replacement);
.write_str(&replacement)
.expect("Failed to update DOM");
} }
} }
} }
@ -443,10 +440,7 @@ pub fn walk_and_embed_assets(
opt_insecure, opt_insecure,
); );
attribute.value.clear(); attribute.value.clear();
attribute attribute.value.push_slice(&replacement);
.value
.write_str(&replacement)
.expect("Failed to update DOM");
} }
} }

View file

@ -6,10 +6,10 @@ use regex::Regex;
use std::collections::HashMap; use std::collections::HashMap;
use url::{ParseError, Url}; use url::{ParseError, Url};
/// This monster of a regex is used to match any kind of URL found in a CSS /// This monster of a regex is used to match any kind of URL found in CSS.
/// stylesheet.
/// ///
/// There's roughly three different categories that a found url could fit into: /// There are roughly three different categories that a found URL could fit
/// into:
/// - Font [found after a src: property in an @font-family rule] /// - Font [found after a src: property in an @font-family rule]
/// - Stylesheet [denoted by an @import before the url /// - Stylesheet [denoted by an @import before the url
/// - Image [covers all other uses of the url() function] /// - Image [covers all other uses of the url() function]
@ -19,22 +19,22 @@ use url::{ParseError, Url};
/// - Where is the part that needs to be replaced (incl any wrapping quotes) /// - Where is the part that needs to be replaced (incl any wrapping quotes)
/// - What is the URL (excl any wrapping quotes) /// - What is the URL (excl any wrapping quotes)
/// ///
/// For understandablility, the regex can be broken down into two parts: /// Essentially, the regex can be broken down into two parts:
/// ///
/// `(?:(?P<import>@import)|(?P<font>src\s*:)\s+)?` /// `(?:(?P<import>@import)|(?P<font>src\s*:)\s+)?`
/// This matches the precursor to a font or css url, and fills in a match under /// This matches the precursor to a font or CSS URL, and fills in a match under
/// either `<import>` (if it's a css url) or `<font>` (if it's a font). /// either `<import>` (if it's a CSS URL) or `<font>` (if it's a font).
/// Determining whether or not it's an image can be done by the negation of both /// Determining whether or not it's an image can be done by the negation of both
/// of these. Either zero or one of these can match. /// of these. Either zero or one of these can match.
/// ///
/// `url\((?P<to_repl>['"]?(?P<url>[^"'\)]+)['"]?)\)` /// `url\((?P<to_repl>['"]?(?P<url>[^"'\)]+)['"]?)\)`
/// This matches the actual URL part of the url, and must always match. It also /// This matches the actual URL part of the url(), and must always match. It also
/// sets `<to_repl>` and `<url>` which correspond to everything within /// sets `<to_repl>` and `<url>` which correspond to everything within
/// `url(...)` and a usable URL, respectively. /// `url(...)` and a usable URL, respectively.
/// ///
/// Note, however, that this does not perform any validation of the found URL. /// Note, however, that this does not perform any validation of the found URL.
/// Malformed CSS could lead to an invalid URL being present. It is therefor /// Malformed CSS could lead to an invalid URL being present. It is therefore
/// recomended that the URL is manually validated. /// recomended that the URL gets manually validated.
const CSS_URL_REGEX_STR: &str = r###"(?:(?:(?P<stylesheet>@import)|(?P<font>src\s*:))\s+)?url\((?P<to_repl>['"]?(?P<url>[^"'\)]+)['"]?)\)"###; const CSS_URL_REGEX_STR: &str = r###"(?:(?:(?P<stylesheet>@import)|(?P<font>src\s*:))\s+)?url\((?P<to_repl>['"]?(?P<url>[^"'\)]+)['"]?)\)"###;
lazy_static! { lazy_static! {
@ -136,7 +136,7 @@ pub fn resolve_css_imports(
Err(_) => continue, // Malformed URL Err(_) => continue, // Malformed URL
}; };
// Download the asset. If it's more CSS, resolve that too // Download the asset. If it's more CSS, resolve that too
let content = if is_stylesheet { let content = if is_stylesheet {
// The link is an @import link // The link is an @import link
retrieve_asset( retrieve_asset(
@ -152,7 +152,7 @@ pub fn resolve_css_imports(
resolve_css_imports( resolve_css_imports(
cache, cache,
&content, &content,
true, //NOW, convert to data URL true, // Finally, convert to a dataurl
&embedded_url, &embedded_url,
opt_no_images, opt_no_images,
opt_user_agent, opt_user_agent,
@ -179,9 +179,9 @@ pub fn resolve_css_imports(
Ok(embedded_url.clone()) Ok(embedded_url.clone())
} }
.unwrap_or_else(|e| { .unwrap_or_else(|e| {
eprintln!("Warning: {}", e,); eprintln!("Warning: {}", e);
//If failed to resolve, replace with absolute URL // If failed to resolve, replace with absolute URL
embedded_url embedded_url
}); });