Skip to content

Commit 8385e75

Browse files
authored
Merge pull request #2951 from ehuss/fa-improvements
Font Awesome fixes and improvements
2 parents 6bf7fad + 8571d70 commit 8385e75

File tree

7 files changed

+17
-14
lines changed

7 files changed

+17
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ The following is a summary of the changes that may require your attention when u
7575

7676
- Updated to a newer version of `pulldown-cmark`. This brings a large number of fixes to markdown processing.
7777
[#2401](https://github.com/rust-lang/mdBook/pull/2401)
78-
- The font-awesome font is no longer loaded as a font. Instead, the corresponding SVG is embedded in the output for the corresponding `<i>` tags. Additionally, a handlebars helper has been added for the `hbs` files.
78+
- The font-awesome font is no longer loaded as a font. Instead, the corresponding SVG is embedded in the output for the corresponding `<i>` tags. Additionally, a handlebars helper has been added for the `hbs` files. This also updates the version from 4.7.0 to 6.2.0, which means some of the icon names and styles have changed. Most of the free icons are in the "solid" set. See the [free icon set](https://fontawesome.com/v6/search) for the available icons.
7979
[#1330](https://github.com/rust-lang/mdBook/pull/1330)
8080
- Changed all internal HTML IDs to have an `mdbook-` prefix. This helps avoid namespace conflicts with header IDs.
8181
[#2808](https://github.com/rust-lang/mdBook/pull/2808)

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;

guide/src/format/configuration/renderers.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,7 @@ The following configuration options are available:
143143
those labels. Defaults to `false`.
144144
- **git-repository-url:** A url to the git repository for the book. If provided
145145
an icon link will be output in the menu bar of the book.
146-
- **git-repository-icon:** The FontAwesome icon class to use for the git
147-
repository link. Defaults to `fab-github` which looks like <i class="fa fab-github"></i>.
148-
If you are not using GitHub, another option to consider is `fa-code-fork` which looks like <i class="fas fa-code-fork"></i>.
146+
- **git-repository-icon:** The Font Awesome icon class to use for the git repository link. Defaults to `fab-github` which looks like <i class="fab fa-github"></i>. If you are not using GitHub, another option to consider is `fas-code-fork` which looks like <i class="fas fa-code-fork"></i>. The start of the string should be `fa-` for regular icons, `fas-` for solid icons, or `fab-` for brand icons. See the [free icon set](https://fontawesome.com/v6/search) for the available icons.
149147
- **edit-url-template:** Edit url template, when provided shows a
150148
"Suggest an edit" button (which looks like <i class="fas fa-pencil"></i>) for directly jumping to editing the currently
151149
viewed page. For e.g. GitHub projects set this to

guide/src/format/mdbook.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,17 @@ HTML tags with class `hidden` will not be shown.
340340

341341
## Font-Awesome icons
342342

343-
mdBook includes a copy of [Font Awesome Free's](https://fontawesome.com)
343+
mdBook includes a copy of version 6 of [Font Awesome Free's](https://fontawesome.com)
344344
MIT-licensed SVG files. It emulates the `<i>` syntax, but converts the results
345345
to inline SVG. Only the regular, solid, and brands icons are included; paid
346346
features like the light icons are not.
347347

348348
For example, given this HTML syntax:
349349

350350
```hbs
351-
The result looks like this: <i class="fas fa-print"></i>
351+
The result looks like this: <i class="fa-solid fa-print"></i>
352352
```
353353

354-
The result looks like this: <i class="fas fa-print"></i>
354+
The result looks like this: <i class="fa-solid fa-print"></i>
355+
356+
See the [free icon set](https://fontawesome.com/v6/search) for the available icons.

guide/src/format/theme/index-hbs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ MIT-licensed SVG files. It accepts three positional arguments:
9595
1. Type: one of "solid", "regular", and "brands" (light and duotone are not
9696
currently supported)
9797
2. Icon: anything chosen from the
98-
[free icon set](https://fontawesome.com/icons?d=gallery&m=free)
98+
[free icon set](https://fontawesome.com/v6/search)
9999
3. ID (optional): if included, an HTML ID attribute will be added to the
100100
icon's wrapping `<span>` tag
101101

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ <h1 id="chapter-1"><a class="header" href="#chapter-1">Chapter 1</a></h1>
33
<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="M272 304h-96C78.8 304 0 382.8 0 480c0 17.67 14.33 32 32 32h384c17.67 0 32-14.33 32-32C448 382.8 369.2 304 272 304zM48.99 464C56.89 400.9 110.8 352 176 352h96c65.16 0 119.1 48.95 127 112H48.99zM224 256c70.69 0 128-57.31 128-128c0-70.69-57.31-128-128-128S96 57.31 96 128C96 198.7 153.3 256 224 256zM224 48c44.11 0 80 35.89 80 80c0 44.11-35.89 80-80 80S144 172.1 144 128C144 83.89 179.9 48 224 48z"/></svg></span></p>
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>
6-
<p><i class="fa fa-does-not-exist"></i></p>
6+
<p><i class="fa fa-does-not-exist"></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>

tests/testsuite/rendering/fontawesome/src/fa.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@
99
<i class="fas fa-heart">Text prevents translation.</i>
1010

1111
<i class="fa fa-does-not-exist"></i>
12+
13+
<i class="fa-solid fa-cat"></i>

0 commit comments

Comments
 (0)