@@ -218,6 +218,7 @@ impl HtmlHandlebars {
218
218
let rendered = fix_code_blocks ( & rendered) ;
219
219
let rendered = add_playground_pre ( & rendered, playground_config, edition) ;
220
220
let rendered = hide_lines ( & rendered, code_config) ;
221
+ let rendered = convert_fontawesome ( & rendered) ;
221
222
222
223
rendered
223
224
}
@@ -258,41 +259,7 @@ impl HtmlHandlebars {
258
259
write_file ( destination, "ayu-highlight.css" , & theme. ayu_highlight_css ) ?;
259
260
write_file ( destination, "highlight.js" , & theme. highlight_js ) ?;
260
261
write_file ( destination, "clipboard.min.js" , & theme. clipboard_js ) ?;
261
- write_file (
262
- destination,
263
- "FontAwesome/css/font-awesome.css" ,
264
- theme:: FONT_AWESOME ,
265
- ) ?;
266
- write_file (
267
- destination,
268
- "FontAwesome/fonts/fontawesome-webfont.eot" ,
269
- theme:: FONT_AWESOME_EOT ,
270
- ) ?;
271
- write_file (
272
- destination,
273
- "FontAwesome/fonts/fontawesome-webfont.svg" ,
274
- theme:: FONT_AWESOME_SVG ,
275
- ) ?;
276
- write_file (
277
- destination,
278
- "FontAwesome/fonts/fontawesome-webfont.ttf" ,
279
- theme:: FONT_AWESOME_TTF ,
280
- ) ?;
281
- write_file (
282
- destination,
283
- "FontAwesome/fonts/fontawesome-webfont.woff" ,
284
- theme:: FONT_AWESOME_WOFF ,
285
- ) ?;
286
- write_file (
287
- destination,
288
- "FontAwesome/fonts/fontawesome-webfont.woff2" ,
289
- theme:: FONT_AWESOME_WOFF2 ,
290
- ) ?;
291
- write_file (
292
- destination,
293
- "FontAwesome/fonts/FontAwesome.ttf" ,
294
- theme:: FONT_AWESOME_TTF ,
295
- ) ?;
262
+
296
263
// Don't copy the stock fonts if the user has specified their own fonts to use.
297
264
if html_config. copy_fonts && theme. fonts_css . is_none ( ) {
298
265
write_file ( destination, "fonts/fonts.css" , theme:: fonts:: CSS ) ?;
@@ -379,6 +346,7 @@ impl HtmlHandlebars {
379
346
handlebars. register_helper ( "next" , Box :: new ( helpers:: navigation:: next) ) ;
380
347
// TODO: remove theme_option in 0.5, it is not needed.
381
348
handlebars. register_helper ( "theme_option" , Box :: new ( helpers:: theme:: theme_option) ) ;
349
+ handlebars. register_helper ( "fa" , Box :: new ( helpers:: fontawesome:: fa_helper) ) ;
382
350
}
383
351
384
352
/// Copy across any additional CSS and JavaScript files which the book
@@ -754,9 +722,19 @@ fn make_data(
754
722
755
723
let git_repository_icon = match html_config. git_repository_icon {
756
724
Some ( ref git_repository_icon) => git_repository_icon,
757
- None => "fa-github" ,
725
+ None => "fab-github" ,
726
+ } ;
727
+ let git_repository_icon_class = match git_repository_icon. split ( '-' ) . next ( ) {
728
+ Some ( "fa" ) => "regular" ,
729
+ Some ( "fas" ) => "solid" ,
730
+ Some ( "fab" ) => "brands" ,
731
+ _ => "regular" ,
758
732
} ;
759
733
data. insert ( "git_repository_icon" . to_owned ( ) , json ! ( git_repository_icon) ) ;
734
+ data. insert (
735
+ "git_repository_icon_class" . to_owned ( ) ,
736
+ json ! ( git_repository_icon_class) ,
737
+ ) ;
760
738
761
739
let mut chapters = vec ! [ ] ;
762
740
@@ -855,6 +833,54 @@ fn insert_link_into_header(
855
833
)
856
834
}
857
835
836
+ // Convert fontawesome `<i>` tags to inline SVG
837
+ fn convert_fontawesome ( html : & str ) -> String {
838
+ use font_awesome_as_a_crate as fa;
839
+
840
+ let regex = Regex :: new ( r##"<i([^>]+)class="([^"]+)"([^>]*)></i>"## ) . unwrap ( ) ;
841
+ regex
842
+ . replace_all ( html, |caps : & Captures < ' _ > | {
843
+ let text = & caps[ 0 ] ;
844
+ let before = & caps[ 1 ] ;
845
+ let classes = & caps[ 2 ] ;
846
+ let after = & caps[ 3 ] ;
847
+
848
+ let mut icon = String :: new ( ) ;
849
+ let mut type_ = fa:: Type :: Regular ;
850
+ let mut other_classes = String :: new ( ) ;
851
+
852
+ for class in classes. split ( " " ) {
853
+ if let Some ( class) = class. strip_prefix ( "fa-" ) {
854
+ icon = class. to_owned ( ) ;
855
+ } else if class == "fa" {
856
+ type_ = fa:: Type :: Regular ;
857
+ } else if class == "fas" {
858
+ type_ = fa:: Type :: Solid ;
859
+ } else if class == "fab" {
860
+ type_ = fa:: Type :: Brands ;
861
+ } else {
862
+ other_classes += " " ;
863
+ other_classes += class;
864
+ }
865
+ }
866
+
867
+ if icon. is_empty ( ) {
868
+ text. to_owned ( )
869
+ } else if let Ok ( svg) = fa:: svg ( type_, & icon) {
870
+ format ! (
871
+ r#"<span{before}class="fa-svg{other_classes}"{after}>{svg}</span>"# ,
872
+ before = before,
873
+ other_classes = other_classes,
874
+ after = after,
875
+ svg = svg
876
+ )
877
+ } else {
878
+ text. to_owned ( )
879
+ }
880
+ } )
881
+ . into_owned ( )
882
+ }
883
+
858
884
// The rust book uses annotations for rustdoc to test code snippets,
859
885
// like the following:
860
886
// ```rust,should_panic
0 commit comments