Skip to content

Commit

Permalink
Merge pull request #100 from jugglerchris/better_selectors
Browse files Browse the repository at this point in the history
Remove a panic and support <font color="...">.
  • Loading branch information
jugglerchris authored Dec 22, 2023
2 parents 875c21c + afaa96f commit 2a1f758
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,13 @@ impl StyleData {
/// Add some CSS source to be included. The source will be parsed
/// and the relevant and supported features extracted.
pub fn add_css(&mut self, css: &str) {
let ss = StyleSheet::parse(css, ParserOptions::default()).unwrap();
html_trace!("add css [[{}]]", css);
let ss = match StyleSheet::parse(css, ParserOptions::default()) {
Ok(ss) => ss,
Err(_e) => {
html_trace!("failed to parse CSS: {}, [[{}]]", _e, css);
return;
}
};

for rule in &ss.rules.0 {
match rule {
Expand Down
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,27 @@ fn process_dom_node<'a, 'b, 'c, T: Write>(
}
}
}
#[cfg(feature = "css")]
expanded_name!(html "font") => {
let mut colour = None;
if context.use_doc_css {
use lightningcss::traits::Parse;
let borrowed = attrs.borrow();
for attr in borrowed.iter() {
if &attr.name.local == "color" {
colour = CssColor::parse_string(&*attr.value)
.ok()
.and_then(|c| TryFrom::try_from(&c).ok());
break;
}
}
}
if let Some(colour) = colour {
pending(handle, move |_, cs| Ok(Some(RenderNode::new(Coloured(colour, vec![RenderNode::new(Container(cs))])))))
} else {
pending(handle, |_, cs| Ok(Some(RenderNode::new(Container(cs)))))
}
}
expanded_name!(html "a") => {
let borrowed = attrs.borrow();
let mut target = None;
Expand Down

0 comments on commit 2a1f758

Please sign in to comment.