From 4b5ea14ee1fc11c20b4e228627f73c90b02a6369 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Wed, 19 Nov 2025 16:04:34 -0800 Subject: [PATCH] Support new font-awesome class names In version 6, Font Awesome changed so that the class names look like `fa-solid fa-cat` instead of `fas fa-cat`. This updates so that it handles this new style. --- crates/mdbook-html/src/html/tree.rs | 10 +++++----- tests/testsuite/rendering.rs | 1 - tests/testsuite/rendering/fontawesome/expected/fa.html | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/crates/mdbook-html/src/html/tree.rs b/crates/mdbook-html/src/html/tree.rs index 0c7c2e4d..5cb97ce3 100644 --- a/crates/mdbook-html/src/html/tree.rs +++ b/crates/mdbook-html/src/html/tree.rs @@ -1030,14 +1030,14 @@ where let i_el = node.value().as_element().unwrap(); let classes = i_el.attr("class").unwrap_or_default(); for class in classes.split(" ") { - if let Some(class) = class.strip_prefix("fa-") { - icon = class.to_owned(); - } else if class == "fa" { + if matches!(class, "fa" | "fa-regular") { type_ = fa::Type::Regular; - } else if class == "fas" { + } else if matches!(class, "fas" | "fa-solid") { type_ = fa::Type::Solid; - } else if class == "fab" { + } else if matches!(class, "fab" | "fa-brands") { type_ = fa::Type::Brands; + } else if let Some(class) = class.strip_prefix("fa-") { + icon = class.to_owned(); } else { new_classes += " "; new_classes += class; diff --git a/tests/testsuite/rendering.rs b/tests/testsuite/rendering.rs index 63bcc70f..421aa5d4 100644 --- a/tests/testsuite/rendering.rs +++ b/tests/testsuite/rendering.rs @@ -53,7 +53,6 @@ fn fontawesome() { 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 - WARN failed to find Font Awesome icon for icon `cat` 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` "#]]); diff --git a/tests/testsuite/rendering/fontawesome/expected/fa.html b/tests/testsuite/rendering/fontawesome/expected/fa.html index 565f7f89..6dfc9de1 100644 --- a/tests/testsuite/rendering/fontawesome/expected/fa.html +++ b/tests/testsuite/rendering/fontawesome/expected/fa.html @@ -4,4 +4,4 @@

Text prevents translation.

-

\ No newline at end of file +

\ No newline at end of file