Added support for <style> tags
This commit is contained in:
parent
1de0fc0961
commit
d574e9a5da
2 changed files with 30 additions and 3 deletions
23
src/html.rs
23
src/html.rs
|
@ -7,6 +7,7 @@ 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::io::{stderr, Write};
|
use std::io::{stderr, Write};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
@ -144,6 +145,7 @@ pub fn walk_and_embed_assets(
|
||||||
Ok((css_data, _)) => resolve_css_imports(
|
Ok((css_data, _)) => resolve_css_imports(
|
||||||
cache,
|
cache,
|
||||||
&css_data,
|
&css_data,
|
||||||
|
true,
|
||||||
&href_full_url,
|
&href_full_url,
|
||||||
opt_user_agent,
|
opt_user_agent,
|
||||||
opt_silent,
|
opt_silent,
|
||||||
|
@ -297,6 +299,27 @@ pub fn walk_and_embed_assets(
|
||||||
if opt_no_css {
|
if opt_no_css {
|
||||||
// Empty inner content of STYLE tags
|
// Empty inner content of STYLE tags
|
||||||
node.children.borrow_mut().clear();
|
node.children.borrow_mut().clear();
|
||||||
|
} else {
|
||||||
|
for node in node.children.borrow_mut().iter_mut() {
|
||||||
|
match node.data {
|
||||||
|
NodeData::Text {ref contents} => {
|
||||||
|
let mut tendril = contents.borrow_mut();
|
||||||
|
let replacement = resolve_css_imports(
|
||||||
|
cache,
|
||||||
|
dbg!(tendril.as_ref()),
|
||||||
|
false,
|
||||||
|
&url,
|
||||||
|
opt_user_agent,
|
||||||
|
opt_silent,
|
||||||
|
opt_insecure,
|
||||||
|
);
|
||||||
|
tendril.clear();
|
||||||
|
tendril.write_str(&replacement)
|
||||||
|
.expect("Failed to update DOM");
|
||||||
|
},
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"form" => {
|
"form" => {
|
||||||
|
|
10
src/utils.rs
10
src/utils.rs
|
@ -85,6 +85,7 @@ pub fn resolve_url<T: AsRef<str>, U: AsRef<str>>(from: T, to: U) -> Result<Strin
|
||||||
pub fn resolve_css_imports(
|
pub fn resolve_css_imports(
|
||||||
cache: &mut HashMap<String, String>,
|
cache: &mut HashMap<String, String>,
|
||||||
css_string: &str,
|
css_string: &str,
|
||||||
|
as_dataurl: bool,
|
||||||
href: &str,
|
href: &str,
|
||||||
opt_user_agent: &str,
|
opt_user_agent: &str,
|
||||||
opt_silent: bool,
|
opt_silent: bool,
|
||||||
|
@ -118,6 +119,7 @@ pub fn resolve_css_imports(
|
||||||
.map(|(content, _)| resolve_css_imports(
|
.map(|(content, _)| resolve_css_imports(
|
||||||
cache,
|
cache,
|
||||||
&content,
|
&content,
|
||||||
|
true, //NOW, convert to data URL
|
||||||
&embedded_url,
|
&embedded_url,
|
||||||
opt_user_agent,
|
opt_user_agent,
|
||||||
opt_silent,
|
opt_silent,
|
||||||
|
@ -154,7 +156,9 @@ pub fn resolve_css_imports(
|
||||||
resolved_css = t.clone();
|
resolved_css = t.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
let encoded_css = data_to_dataurl("text/css", resolved_css.as_bytes());
|
if as_dataurl {
|
||||||
|
data_to_dataurl("text/css", resolved_css.as_bytes())
|
||||||
encoded_css.to_string()
|
} else {
|
||||||
|
resolved_css
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue