Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 1 addition & 33 deletions crates/mdbook-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ pub enum RustEdition {
}

/// Configuration for the HTML renderer.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case", deny_unknown_fields)]
#[non_exhaustive]
pub struct HtmlConfig {
Expand All @@ -426,8 +426,6 @@ pub struct HtmlConfig {
pub smart_punctuation: bool,
/// Should mathjax be enabled?
pub mathjax_support: bool,
/// Whether to fonts.css and respective font files to the output directory.
pub copy_fonts: bool,
/// Additional CSS stylesheets to include in the rendered page's `<head>`.
pub additional_css: Vec<PathBuf>,
/// Additional JS scripts to include at the bottom of the rendered page's
Expand Down Expand Up @@ -481,36 +479,6 @@ pub struct HtmlConfig {
pub hash_files: bool,
}

impl Default for HtmlConfig {
fn default() -> HtmlConfig {
HtmlConfig {
theme: None,
default_theme: None,
preferred_dark_theme: None,
smart_punctuation: false,
mathjax_support: false,
copy_fonts: true,
additional_css: Vec::new(),
additional_js: Vec::new(),
fold: Fold::default(),
playground: Playground::default(),
code: Code::default(),
print: Print::default(),
no_section_label: false,
search: None,
git_repository_url: None,
git_repository_icon: None,
edit_url_template: None,
input_404: None,
site_url: None,
cname: None,
live_reload_endpoint: None,
redirect: HashMap::new(),
hash_files: false,
}
}
}

impl HtmlConfig {
/// Returns the directory of theme from the provided root directory. If the
/// directory is not present it will append the default directory of "theme"
Expand Down
2 changes: 0 additions & 2 deletions crates/mdbook-html/front-end/templates/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@

<!-- Fonts -->
<link rel="stylesheet" href="{{ resource "FontAwesome/css/font-awesome.css" }}">
{{#if copy_fonts}}
<link rel="stylesheet" href="{{ resource "fonts/fonts.css" }}">
{{/if}}

<!-- Highlight.js Stylesheets -->
<link rel="stylesheet" id="highlight-css" href="{{ resource "highlight.css" }}">
Expand Down
2 changes: 0 additions & 2 deletions crates/mdbook-html/front-end/templates/toc.html.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
{{/if}}
<!-- Fonts -->
<link rel="stylesheet" href="{{ resource "FontAwesome/css/font-awesome.css" }}">
{{#if copy_fonts}}
<link rel="stylesheet" href="{{ resource "fonts/fonts.css" }}">
{{/if}}
<!-- Custom theme stylesheets -->
{{#each additional_css}}
<link rel="stylesheet" href="{{ resource this }}">
Expand Down
5 changes: 0 additions & 5 deletions crates/mdbook-html/src/html_handlebars/hbs_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,6 @@ fn make_data(
data.insert("mathjax_support".to_owned(), json!(true));
}

// This `matches!` checks for a non-empty file.
if html_config.copy_fonts || matches!(theme.fonts_css.as_deref(), Some([_, ..])) {
data.insert("copy_fonts".to_owned(), json!(true));
}

// Add check to see if there is an additional style
if !html_config.additional_css.is_empty() {
let mut css = Vec::new();
Expand Down
11 changes: 2 additions & 9 deletions crates/mdbook-html/src/html_handlebars/static_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use super::helpers::resources::ResourceHelper;
use crate::theme::{self, Theme, playground_editor};
use anyhow::{Context, Result};
use log::{debug, warn};
use log::debug;
use mdbook_core::config::HtmlConfig;
use mdbook_core::utils;
use std::borrow::Cow;
Expand Down Expand Up @@ -84,7 +84,7 @@ impl StaticFiles {
theme::FONT_AWESOME_WOFF2,
);
this.add_builtin("FontAwesome/fonts/FontAwesome.ttf", theme::FONT_AWESOME_TTF);
if html_config.copy_fonts && theme.fonts_css.is_none() {
if theme.fonts_css.is_none() {
this.add_builtin("fonts/fonts.css", theme::fonts::CSS);
for (file_name, contents) in theme::fonts::LICENSES.iter() {
this.add_builtin(file_name, contents);
Expand All @@ -101,13 +101,6 @@ impl StaticFiles {
this.add_builtin("fonts/fonts.css", fonts_css);
}
}
if !html_config.copy_fonts && theme.fonts_css.is_none() {
warn!(
"output.html.copy-fonts is deprecated.\n\
This book appears to have copy-fonts=false in book.toml without a fonts.css file.\n\
Add an empty `theme/fonts/fonts.css` file to squelch this warning."
);
}

let playground_config = &html_config.playground;

Expand Down
5 changes: 0 additions & 5 deletions guide/src/format/configuration/renderers.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ default-theme = "light"
preferred-dark-theme = "navy"
smart-punctuation = true
mathjax-support = false
copy-fonts = true
additional-css = ["custom.css", "custom2.css"]
additional-js = ["custom.js"]
no-section-label = false
Expand Down Expand Up @@ -127,10 +126,6 @@ The following configuration options are available:
Defaults to `false`.
- **mathjax-support:** Adds support for [MathJax](../mathjax.md). Defaults to
`false`.
- **copy-fonts:** (**Deprecated**) If `true` (the default), mdBook uses its built-in fonts which are copied to the output directory.
If `false`, the built-in fonts will not be used.
This option is deprecated. If you want to define your own custom fonts,
create a `theme/fonts/fonts.css` file and store the fonts in the `theme/fonts/` directory.
- **additional-css:** If you need to slightly change the appearance of your book
without overwriting the whole style, you can specify a set of stylesheets that
will be loaded after the default ones where you can surgically change the
Expand Down
33 changes: 7 additions & 26 deletions tests/testsuite/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,45 +139,26 @@ book/fonts/myfont.woff
);
}

// copy-fonts=false, no theme, deprecated
// Empty fonts.css should not copy the default fonts.
#[test]
fn copy_fonts_false_no_theme() {
BookTest::from_dir("theme/copy_fonts_false_no_theme")
fn empty_fonts_css() {
BookTest::from_dir("theme/empty_fonts_css")
.run("build", |cmd| {
cmd.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Running the html backend
[TIMESTAMP] [WARN] (mdbook_html::html_handlebars::static_files): output.html.copy-fonts is deprecated.
This book appears to have copy-fonts=false in book.toml without a fonts.css file.
Add an empty `theme/fonts/fonts.css` file to squelch this warning.
[TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`

"#]]);
})
.check_file_doesnt_contain("book/index.html", "fonts.css")
.check_file_list("book/fonts", str![[""]]);
}

// copy-fonts=false, empty fonts.css
#[test]
fn copy_fonts_false_with_empty_fonts_css() {
BookTest::from_dir("theme/copy_fonts_false_with_empty_fonts_css")
.run("build", |cmd| {
cmd.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Running the html backend
[TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`

"#]]);
})
.check_file_doesnt_contain("book/index.html", "fonts.css")
.check_file_contains("book/index.html", "fonts.css")
.check_file_list("book/fonts", str![[""]]);
}

// copy-fonts=false, fonts.css has contents
// Custom fonts.css file shouldn't copy default fonts.
#[test]
fn copy_fonts_false_with_fonts_css() {
BookTest::from_dir("theme/copy_fonts_false_with_fonts_css")
fn custom_fonts_css() {
BookTest::from_dir("theme/custom_fonts_css")
.run("build", |cmd| {
cmd.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started
Expand Down
2 changes: 0 additions & 2 deletions tests/testsuite/theme/copy_fonts_false_no_theme/book.toml

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 2 additions & 0 deletions tests/testsuite/theme/custom_fonts_css/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[book]
title = "custom_fonts_css"
2 changes: 2 additions & 0 deletions tests/testsuite/theme/empty_fonts_css/book.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[book]
title = "empty_fonts_css"
Loading