Skip to content

Commit b3bd103

Browse files
committed
Add a warning when a Font Awesome font is missing
With the migration to Font Awesome 6, I'm running into books where the icon names are missing or have changed. This adds a warning to help identify those situations.
1 parent 7e5fa35 commit b3bd103

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

crates/mdbook-html/src/html/tree.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -977,19 +977,29 @@ where
977977
new_classes += class;
978978
}
979979
}
980+
if icon.is_empty() {
981+
continue;
982+
}
980983

981-
if !icon.is_empty()
982-
&& let Ok(svg) = fa::svg(type_, &icon)
983-
{
984-
let mut span = Element::new("span");
985-
span.insert_attr("class", new_classes.into());
986-
for (name, value) in &i_el.attrs {
987-
if *name != attr_qual_name!("class") {
988-
span.attrs.insert(name.clone(), value.clone());
984+
match fa::svg(type_, &icon) {
985+
Ok(svg) => {
986+
let mut span = Element::new("span");
987+
span.insert_attr("class", new_classes.into());
988+
for (name, value) in &i_el.attrs {
989+
if *name != attr_qual_name!("class") {
990+
span.attrs.insert(name.clone(), value.clone());
991+
}
989992
}
993+
*node.value() = Node::Element(span);
994+
node.append(Node::RawData(svg.into()));
995+
}
996+
Err(e) => {
997+
warn!(
998+
"failed to find Font Awesome icon for icon `{icon}` \
999+
with type `{type_}` in `{}`: {e}",
1000+
self.options.path.display()
1001+
);
9901002
}
991-
*node.value() = Node::Element(span);
992-
node.append(Node::RawData(svg.into()));
9931003
}
9941004
}
9951005
}

tests/testsuite/rendering.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ fn fontawesome() {
5252
cmd.expect_stderr(str![[r#"
5353
INFO Book building has started
5454
INFO Running the html backend
55+
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
5556
INFO HTML book written to `[ROOT]/book`
5657
5758
"#]]);

0 commit comments

Comments
 (0)