diff --git a/crates/mdbook-html/src/html/tree.rs b/crates/mdbook-html/src/html/tree.rs index 5a0786ea..4184740d 100644 --- a/crates/mdbook-html/src/html/tree.rs +++ b/crates/mdbook-html/src/html/tree.rs @@ -977,19 +977,29 @@ where new_classes += class; } } + if icon.is_empty() { + continue; + } - if !icon.is_empty() - && let Ok(svg) = fa::svg(type_, &icon) - { - let mut span = Element::new("span"); - span.insert_attr("class", new_classes.into()); - for (name, value) in &i_el.attrs { - if *name != attr_qual_name!("class") { - span.attrs.insert(name.clone(), value.clone()); + match fa::svg(type_, &icon) { + Ok(svg) => { + let mut span = Element::new("span"); + span.insert_attr("class", new_classes.into()); + for (name, value) in &i_el.attrs { + if *name != attr_qual_name!("class") { + span.attrs.insert(name.clone(), value.clone()); + } } + *node.value() = Node::Element(span); + node.append(Node::RawData(svg.into())); + } + Err(e) => { + warn!( + "failed to find Font Awesome icon for icon `{icon}` \ + with type `{type_}` in `{}`: {e}", + self.options.path.display() + ); } - *node.value() = Node::Element(span); - node.append(Node::RawData(svg.into())); } } } diff --git a/tests/testsuite/rendering.rs b/tests/testsuite/rendering.rs index b2281eae..7f2fffa9 100644 --- a/tests/testsuite/rendering.rs +++ b/tests/testsuite/rendering.rs @@ -52,6 +52,7 @@ fn fontawesome() { cmd.expect_stderr(str![[r#" INFO Book building has started INFO Running the html backend + WARN failed to find Font Awesome icon for icon `does-not-exist` with type `regular` in `fa.md`: Invalid Font Awesome icon name: visit https://fontawesome.com/icons?d=gallery&m=free to see valid names INFO HTML book written to `[ROOT]/book` "#]]);