mirror of
https://github.com/rust-lang/mdBook.git
synced 2025-12-27 10:16:09 -05:00
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.
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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`
|
||||
|
||||
"#]]);
|
||||
|
||||
Reference in New Issue
Block a user