Remove copy-fonts

This removes the deprecated `output.html.copy-fonts` option. This was
deprecated in https://github.com/rust-lang/mdBook/pull/1987. The
behavior now is that the default fonts are copied over unless there is a
custom `theme/fonts/fonts.css` file.
This commit is contained in:
Eric Huss 2025-08-12 17:55:41 -07:00
parent 7e0949175a
commit 3e5ec749ba
18 changed files with 14 additions and 89 deletions

View file

@ -411,7 +411,7 @@ pub enum RustEdition {
} }
/// Configuration for the HTML renderer. /// 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)] #[serde(default, rename_all = "kebab-case", deny_unknown_fields)]
#[non_exhaustive] #[non_exhaustive]
pub struct HtmlConfig { pub struct HtmlConfig {
@ -426,8 +426,6 @@ pub struct HtmlConfig {
pub smart_punctuation: bool, pub smart_punctuation: bool,
/// Should mathjax be enabled? /// Should mathjax be enabled?
pub mathjax_support: bool, 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>`. /// Additional CSS stylesheets to include in the rendered page's `<head>`.
pub additional_css: Vec<PathBuf>, pub additional_css: Vec<PathBuf>,
/// Additional JS scripts to include at the bottom of the rendered page's /// Additional JS scripts to include at the bottom of the rendered page's
@ -481,36 +479,6 @@ pub struct HtmlConfig {
pub hash_files: bool, 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 { impl HtmlConfig {
/// Returns the directory of theme from the provided root directory. If the /// Returns the directory of theme from the provided root directory. If the
/// directory is not present it will append the default directory of "theme" /// directory is not present it will append the default directory of "theme"

View file

@ -34,9 +34,7 @@
<!-- Fonts --> <!-- Fonts -->
<link rel="stylesheet" href="{{ resource "FontAwesome/css/font-awesome.css" }}"> <link rel="stylesheet" href="{{ resource "FontAwesome/css/font-awesome.css" }}">
{{#if copy_fonts}}
<link rel="stylesheet" href="{{ resource "fonts/fonts.css" }}"> <link rel="stylesheet" href="{{ resource "fonts/fonts.css" }}">
{{/if}}
<!-- Highlight.js Stylesheets --> <!-- Highlight.js Stylesheets -->
<link rel="stylesheet" id="highlight-css" href="{{ resource "highlight.css" }}"> <link rel="stylesheet" id="highlight-css" href="{{ resource "highlight.css" }}">

View file

@ -29,9 +29,7 @@
{{/if}} {{/if}}
<!-- Fonts --> <!-- Fonts -->
<link rel="stylesheet" href="{{ resource "FontAwesome/css/font-awesome.css" }}"> <link rel="stylesheet" href="{{ resource "FontAwesome/css/font-awesome.css" }}">
{{#if copy_fonts}}
<link rel="stylesheet" href="{{ resource "fonts/fonts.css" }}"> <link rel="stylesheet" href="{{ resource "fonts/fonts.css" }}">
{{/if}}
<!-- Custom theme stylesheets --> <!-- Custom theme stylesheets -->
{{#each additional_css}} {{#each additional_css}}
<link rel="stylesheet" href="{{ resource this }}"> <link rel="stylesheet" href="{{ resource this }}">

View file

@ -557,11 +557,6 @@ fn make_data(
data.insert("mathjax_support".to_owned(), json!(true)); 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 // Add check to see if there is an additional style
if !html_config.additional_css.is_empty() { if !html_config.additional_css.is_empty() {
let mut css = Vec::new(); let mut css = Vec::new();

View file

@ -3,7 +3,7 @@
use super::helpers::resources::ResourceHelper; use super::helpers::resources::ResourceHelper;
use crate::theme::{self, Theme, playground_editor}; use crate::theme::{self, Theme, playground_editor};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use log::{debug, warn}; use log::debug;
use mdbook_core::config::HtmlConfig; use mdbook_core::config::HtmlConfig;
use mdbook_core::utils; use mdbook_core::utils;
use std::borrow::Cow; use std::borrow::Cow;
@ -84,7 +84,7 @@ impl StaticFiles {
theme::FONT_AWESOME_WOFF2, theme::FONT_AWESOME_WOFF2,
); );
this.add_builtin("FontAwesome/fonts/FontAwesome.ttf", theme::FONT_AWESOME_TTF); 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); this.add_builtin("fonts/fonts.css", theme::fonts::CSS);
for (file_name, contents) in theme::fonts::LICENSES.iter() { for (file_name, contents) in theme::fonts::LICENSES.iter() {
this.add_builtin(file_name, contents); this.add_builtin(file_name, contents);
@ -101,13 +101,6 @@ impl StaticFiles {
this.add_builtin("fonts/fonts.css", fonts_css); 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; let playground_config = &html_config.playground;

View file

@ -99,7 +99,6 @@ default-theme = "light"
preferred-dark-theme = "navy" preferred-dark-theme = "navy"
smart-punctuation = true smart-punctuation = true
mathjax-support = false mathjax-support = false
copy-fonts = true
additional-css = ["custom.css", "custom2.css"] additional-css = ["custom.css", "custom2.css"]
additional-js = ["custom.js"] additional-js = ["custom.js"]
no-section-label = false no-section-label = false
@ -127,10 +126,6 @@ The following configuration options are available:
Defaults to `false`. Defaults to `false`.
- **mathjax-support:** Adds support for [MathJax](../mathjax.md). Defaults to - **mathjax-support:** Adds support for [MathJax](../mathjax.md). Defaults to
`false`. `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 - **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 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 will be loaded after the default ones where you can surgically change the

View file

@ -139,29 +139,10 @@ book/fonts/myfont.woff
); );
} }
// copy-fonts=false, no theme, deprecated // Empty fonts.css should not copy the default fonts.
#[test] #[test]
fn copy_fonts_false_no_theme() { fn empty_fonts_css() {
BookTest::from_dir("theme/copy_fonts_false_no_theme") 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| { .run("build", |cmd| {
cmd.expect_stderr(str![[r#" cmd.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started [TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started
@ -170,14 +151,14 @@ fn copy_fonts_false_with_empty_fonts_css() {
"#]]); "#]]);
}) })
.check_file_doesnt_contain("book/index.html", "fonts.css") .check_file_contains("book/index.html", "fonts.css")
.check_file_list("book/fonts", str![[""]]); .check_file_list("book/fonts", str![[""]]);
} }
// copy-fonts=false, fonts.css has contents // Custom fonts.css file shouldn't copy default fonts.
#[test] #[test]
fn copy_fonts_false_with_fonts_css() { fn custom_fonts_css() {
BookTest::from_dir("theme/copy_fonts_false_with_fonts_css") BookTest::from_dir("theme/custom_fonts_css")
.run("build", |cmd| { .run("build", |cmd| {
cmd.expect_stderr(str![[r#" cmd.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started [TIMESTAMP] [INFO] (mdbook_driver::mdbook): Book building has started

View file

@ -1,2 +0,0 @@
[output.html]
copy-fonts = false

View file

@ -1,2 +0,0 @@
[output.html]
copy-fonts = false

View file

@ -1,2 +0,0 @@
[output.html]
copy-fonts = false

View file

@ -1 +0,0 @@
- [Intro](index.md)

View file

@ -0,0 +1,2 @@
[book]
title = "custom_fonts_css"

View file

@ -0,0 +1,2 @@
[book]
title = "empty_fonts_css"