Skip to content

Commit 4b5ea14

Browse files
committed
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.
1 parent c53379e commit 4b5ea14

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,14 +1030,14 @@ where
10301030
let i_el = node.value().as_element().unwrap();
10311031
let classes = i_el.attr("class").unwrap_or_default();
10321032
for class in classes.split(" ") {
1033-
if let Some(class) = class.strip_prefix("fa-") {
1034-
icon = class.to_owned();
1035-
} else if class == "fa" {
1033+
if matches!(class, "fa" | "fa-regular") {
10361034
type_ = fa::Type::Regular;
1037-
} else if class == "fas" {
1035+
} else if matches!(class, "fas" | "fa-solid") {
10381036
type_ = fa::Type::Solid;
1039-
} else if class == "fab" {
1037+
} else if matches!(class, "fab" | "fa-brands") {
10401038
type_ = fa::Type::Brands;
1039+
} else if let Some(class) = class.strip_prefix("fa-") {
1040+
icon = class.to_owned();
10411041
} else {
10421042
new_classes += " ";
10431043
new_classes += class;

tests/testsuite/rendering.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ fn fontawesome() {
5353
INFO Book building has started
5454
INFO Running the html backend
5555
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
56-
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
5756
INFO HTML book written to `[ROOT]/book`
5857
5958
"#]]);

tests/testsuite/rendering/fontawesome/expected/fa.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ <h1 id="chapter-1"><a class="header" href="#chapter-1">Chapter 1</a></h1>
44
<p><span class="fa-svg"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M448 48V384C385 407 366 416 329 416C266 416 242 384 179 384C159 384 143 388 128 392V328C143 324 159 320 179 320C242 320 266 352 329 352C349 352 364 349 384 343V135C364 141 349 144 329 144C266 144 242 112 179 112C128 112 104 133 64 141V448C64 466 50 480 32 480S0 466 0 448V64C0 46 14 32 32 32S64 46 64 64V77C104 69 128 48 179 48C242 48 266 80 329 80C366 80 385 71 448 48Z"/></svg></span></p>
55
<p><i class="fas fa-heart">Text prevents translation.</i></p>
66
<p><i class="fa fa-does-not-exist"></i></p>
7-
<p><i class="fa-solid fa-cat"></i></p>
7+
<p><span class="fa-svg"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--! Font Awesome Free 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free (Icons: CC BY 4.0, Fonts: SIL OFL 1.1, Code: MIT License) Copyright 2022 Fonticons, Inc. --><path d="M288 192h17.1c22.1 38.3 63.5 64 110.9 64c11 0 21.8-1.4 32-4v4 32V480c0 17.7-14.3 32-32 32s-32-14.3-32-32V339.2L248 448h56c17.7 0 32 14.3 32 32s-14.3 32-32 32H160c-53 0-96-43-96-96V192.5c0-16.1-12-29.8-28-31.8l-7.9-1C10.5 157.6-1.9 141.6 .2 124s18.2-30 35.7-27.8l7.9 1c48 6 84.1 46.8 84.1 95.3v85.3c34.4-51.7 93.2-85.8 160-85.8zm160 26.5v0c-10 3.5-20.8 5.5-32 5.5c-28.4 0-54-12.4-71.6-32h0c-3.7-4.1-7-8.5-9.9-13.2C325.3 164 320 146.6 320 128v0V32 12 10.7C320 4.8 324.7 .1 330.6 0h.2c3.3 0 6.4 1.6 8.4 4.2l0 .1L352 21.3l27.2 36.3L384 64h64l4.8-6.4L480 21.3 492.8 4.3l0-.1c2-2.6 5.1-4.2 8.4-4.2h.2C507.3 .1 512 4.8 512 10.7V12 32v96c0 17.3-4.6 33.6-12.6 47.6c-11.3 19.8-29.6 35.2-51.4 42.9zM400 128c0-8.8-7.2-16-16-16s-16 7.2-16 16s7.2 16 16 16s16-7.2 16-16zm48 16c8.8 0 16-7.2 16-16s-7.2-16-16-16s-16 7.2-16 16s7.2 16 16 16z"/></svg></span></p>

0 commit comments

Comments
 (0)