Skip to content

Commit

Permalink
Add docs changes, fix fontawesome i tag parsing, remove extra templat…
Browse files Browse the repository at this point in the history
…e svg
  • Loading branch information
uncenter committed Nov 15, 2024
1 parent 9004849 commit 39d7615
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
4 changes: 2 additions & 2 deletions guide/src/format/configuration/renderers.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ additional-css = ["custom.css", "custom2.css"]
additional-js = ["custom.js"]
no-section-label = false
git-repository-url = "https://github.com/rust-lang/mdBook"
git-repository-icon = "fa-github"
git-repository-icon = "fab-github"
edit-url-template = "https://github.com/rust-lang/mdBook/edit/master/guide/{path}"
site-url = "/example-book/"
cname = "myproject.rs"
Expand Down Expand Up @@ -147,7 +147,7 @@ The following configuration options are available:
- **git-repository-url:** A url to the git repository for the book. If provided
an icon link will be output in the menu bar of the book.
- **git-repository-icon:** The FontAwesome icon class to use for the git
repository link. Defaults to `fa-github` which looks like <i class="fa fa-github"></i>.
repository link. Defaults to `fab-github` which looks like <i class="fa fab-github"></i>.
If you are not using GitHub, another option to consider is `fa-code-fork` which looks like <i class="fa fa-code-fork"></i>.
- **edit-url-template:** Edit url template, when provided shows a
"Suggest an edit" button (which looks like <i class="fa fa-edit"></i>) for directly jumping to editing the currently
Expand Down
16 changes: 16 additions & 0 deletions guide/src/format/mdbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,19 @@ fatigue," where people are trained to ignore them because they usually don't
matter for what they're doing.

</div>


## Font-Awesome icons

mdBook includes a copy of [Font Awesome's](https://fontawesome.com) free
MIT-licensed SVG files. It emulates the `<i>` syntax, but converts the results
to inline SVG. Only the regular, solid, and brands icons are included; paid
features such as the light icons are not.

For example, given this HTML syntax:

```hbs
The result looks like this: <i class="fa fas-print"></i>
```

The result looks like this: <i class="fa fas-print"></i>
26 changes: 14 additions & 12 deletions src/renderer/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,18 +850,20 @@ fn convert_fontawesome(html: &str) -> String {
let mut other_classes = String::new();

for class in classes.split(" ") {
if let Some(class) = class.strip_prefix("fa-") {
icon = class.to_owned();
} else if class == "fa" {
type_ = fa::Type::Regular;
} else if class == "fas" {
type_ = fa::Type::Solid;
} else if class == "fab" {
type_ = fa::Type::Brands;
} else {
other_classes += " ";
other_classes += class;
if let Some((prefix, remainder)) = class.split_once('-') {
if let Some(t) = match prefix {
"fa" => Some(fa::Type::Regular),
"fas" => Some(fa::Type::Solid),
"fab" => Some(fa::Type::Brands),
_ => None,
} {
type_ = t;
icon = remainder.to_owned();
continue;
}
}
other_classes += " ";
other_classes += class;
}

if icon.is_empty() {
Expand All @@ -870,7 +872,7 @@ fn convert_fontawesome(html: &str) -> String {
format!(
r#"<span{before}class="fa-svg{other_classes}"{after}>{svg}</span>"#,
before = before,
other_classes = other_classes,
other_classes = other_classes.replace(" fa", ""),
after = after,
svg = svg
)
Expand Down
1 change: 0 additions & 1 deletion src/theme/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@

<template id="fa-eye">{{fa "regular" "eye"}}</template>
<template id="fa-eye-slash">{{fa "regular" "eye-slash"}}</template>
<template id="fa-copy">{{fa "regular" "copy"}}</template>
<template id="fa-play">{{fa "solid" "play"}}</template>
<template id="fa-clock-rotate-left">{{fa "solid" "clock-rotate-left"}}</template>

Expand Down

0 comments on commit 39d7615

Please sign in to comment.