Finish move of hbs_renderer to mdbook-html

This updates everything for the move of hbs_renderer to mdbook-html.
This commit is contained in:
Eric Huss
2025-07-21 20:45:14 -07:00
parent 06324d8b24
commit 7eccd1d556
15 changed files with 83 additions and 71 deletions

20
Cargo.lock generated
View File

@@ -1257,17 +1257,13 @@ checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3"
name = "mdbook"
version = "0.5.0-alpha.1"
dependencies = [
"ammonia",
"anyhow",
"axum",
"chrono",
"clap",
"clap_complete",
"elasticlunr-rs",
"env_logger",
"futures-util",
"handlebars",
"hex",
"ignore",
"log",
"mdbook-core",
@@ -1281,14 +1277,12 @@ dependencies = [
"notify-debouncer-mini",
"opener",
"pathdiff",
"pretty_assertions",
"pulldown-cmark 0.10.3",
"regex",
"select",
"semver",
"serde",
"serde_json",
"sha2",
"shlex",
"snapbox",
"tempfile",
@@ -1317,9 +1311,23 @@ dependencies = [
name = "mdbook-html"
version = "0.5.0-alpha.1"
dependencies = [
"ammonia",
"anyhow",
"elasticlunr-rs",
"handlebars",
"hex",
"log",
"mdbook-core",
"mdbook-markdown",
"mdbook-renderer",
"pretty_assertions",
"pulldown-cmark 0.10.3",
"regex",
"serde",
"serde_json",
"sha2",
"tempfile",
"toml",
]
[[package]]

View File

@@ -21,7 +21,11 @@ repository = "https://github.com/rust-lang/mdBook"
rust-version = "1.85.0" # Keep in sync with installation.md and .github/workflows/main.yml
[workspace.dependencies]
ammonia = "4.1.1"
anyhow = "1.0.98"
elasticlunr-rs = "3.0.2"
handlebars = "6.3.2"
hex = "0.4.3"
log = "0.4.27"
mdbook-core = { path = "crates/mdbook-core" }
mdbook-html = { path = "crates/mdbook-html" }
@@ -30,10 +34,12 @@ mdbook-preprocessor = { path = "crates/mdbook-preprocessor" }
mdbook-renderer = { path = "crates/mdbook-renderer" }
mdbook-summary = { path = "crates/mdbook-summary" }
memchr = "2.7.5"
pretty_assertions = "1.4.1"
pulldown-cmark = { version = "0.10.3", default-features = false, features = ["html"] } # Do not update, part of the public api.
regex = "1.11.1"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
sha2 = "0.10.9"
tempfile = "3.20.0"
toml = "0.5.11" # Do not update, see https://github.com/rust-lang/mdBook/issues/2037
@@ -61,8 +67,6 @@ chrono = { version = "0.4.24", default-features = false, features = ["clock"] }
clap = { version = "4.3.12", features = ["cargo", "wrap_help"] }
clap_complete = "4.3.2"
env_logger = "0.11.1"
handlebars = "6.0"
hex = "0.4.3"
log.workspace = true
mdbook-core.workspace = true
mdbook-html.workspace = true
@@ -76,7 +80,6 @@ pulldown-cmark.workspace = true
regex.workspace = true
serde.workspace = true
serde_json.workspace = true
sha2 = "0.10.8"
shlex = "1.3.0"
tempfile.workspace = true
toml.workspace = true
@@ -95,22 +98,17 @@ tokio = { version = "1.43.1", features = ["macros", "rt-multi-thread"], optional
axum = { version = "0.8.0", features = ["ws"], optional = true }
tower-http = { version = "0.6.0", features = ["fs", "trace"], optional = true }
# Search feature
elasticlunr-rs = { version = "3.0.2", optional = true }
ammonia = { version = "4.0.0", optional = true }
[dev-dependencies]
select = "0.6.0"
semver = "1.0.17"
snapbox = { version = "0.6.21", features = ["diff", "dir", "term-svg", "regex", "json"] }
pretty_assertions = "1.3.0"
walkdir = "2.3.3"
[features]
default = ["watch", "serve", "search"]
watch = ["dep:notify", "dep:notify-debouncer-mini", "dep:ignore", "dep:pathdiff", "dep:walkdir"]
serve = ["dep:futures-util", "dep:tokio", "dep:axum", "dep:tower-http"]
search = ["dep:elasticlunr-rs", "dep:ammonia", "mdbook-html/search"]
search = ["mdbook-html/search"]
[[bin]]
doc = false

View File

@@ -8,14 +8,28 @@ repository.workspace = true
rust-version.workspace = true
[dependencies]
ammonia = { workspace = true, optional = true }
anyhow.workspace = true
elasticlunr-rs = { workspace = true, optional = true }
handlebars.workspace = true
hex.workspace = true
log.workspace = true
mdbook-core.workspace = true
mdbook-markdown.workspace = true
mdbook-renderer.workspace = true
pulldown-cmark.workspace = true
regex.workspace = true
serde.workspace = true
serde_json.workspace = true
sha2.workspace = true
[dev-dependencies]
pretty_assertions.workspace = true
tempfile.workspace = true
toml.workspace = true
[lints]
workspace = true
[features]
search = []
search = ["dep:ammonia", "dep:elasticlunr-rs"]

View File

@@ -1,8 +1,17 @@
use crate::book::{Book, BookItem};
use crate::renderer::html_handlebars::StaticFiles;
use crate::renderer::html_handlebars::helpers;
use crate::renderer::{RenderContext, Renderer};
use super::helpers;
use super::static_files::StaticFiles;
use crate::theme::Theme;
use anyhow::{Context, Result, bail};
use handlebars::Handlebars;
use log::{debug, info, trace, warn};
use mdbook_core::book::{Book, BookItem};
use mdbook_core::config::{BookConfig, Code, Config, HtmlConfig, Playground, RustEdition};
use mdbook_core::utils;
use mdbook_core::utils::fs::get_404_output_file;
use mdbook_markdown::{render_markdown, render_markdown_with_path};
use mdbook_renderer::{RenderContext, Renderer};
use regex::{Captures, Regex};
use serde_json::json;
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::collections::HashMap;
@@ -10,18 +19,6 @@ use std::fs::{self, File};
use std::path::{Path, PathBuf};
use std::sync::LazyLock;
use anyhow::{Context, Result, bail};
use handlebars::Handlebars;
use log::{debug, info, trace, warn};
use mdbook_core::config::{BookConfig, Code, Config, HtmlConfig, Playground, RustEdition};
use mdbook_core::utils;
use mdbook_core::utils::fs::get_404_output_file;
use mdbook_html::theme::Theme;
use mdbook_markdown::{render_markdown, render_markdown_with_path};
use regex::{Captures, Regex};
use serde_json::json;
/// The HTML renderer for mdBook.
#[derive(Default)]
pub struct HtmlHandlebars;

View File

@@ -1,9 +1,7 @@
pub use self::hbs_renderer::HtmlHandlebars;
pub use self::static_files::StaticFiles;
mod hbs_renderer;
mod helpers;
mod static_files;
#[cfg(feature = "search")]
mod search;
mod static_files;
pub use self::hbs_renderer::HtmlHandlebars;

View File

@@ -1,21 +1,19 @@
use super::static_files::StaticFiles;
use crate::theme::searcher;
use anyhow::{Context, Result, bail};
use elasticlunr::{Index, IndexBuilder};
use log::{debug, warn};
use mdbook_core::book::{Book, BookItem, Chapter};
use mdbook_core::config::{Search, SearchChapterSettings};
use mdbook_core::utils;
use mdbook_markdown::new_cmark_parser;
use pulldown_cmark::*;
use serde::Serialize;
use std::borrow::Cow;
use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use std::sync::LazyLock;
use anyhow::{Context, Result, bail};
use elasticlunr::{Index, IndexBuilder};
use log::{debug, warn};
use mdbook_core::config::{Search, SearchChapterSettings};
use mdbook_core::utils;
use mdbook_html::theme::searcher;
use mdbook_markdown::new_cmark_parser;
use pulldown_cmark::*;
use serde::Serialize;
use crate::book::{Book, BookItem, Chapter};
use crate::renderer::html_handlebars::StaticFiles;
const MAX_WORD_LENGTH_TO_INDEX: usize = 80;
/// Tokenizes in the same way as elasticlunr-rs (for English), but also drops long tokens.
@@ -394,7 +392,7 @@ fn chapter_settings_priority() {
"cli/inner" = { enable = true }
"foo" = {} # Just to make sure empty table is allowed.
"#;
let cfg: crate::Config = toml::from_str(cfg).unwrap();
let cfg: mdbook_core::config::Config = toml::from_str(cfg).unwrap();
let html = cfg.html_config().unwrap();
let chapter_configs = sort_search_config(&html.search.unwrap().chapter);
for (path, enable) in [

View File

@@ -1,13 +1,11 @@
//! Support for writing static files.
use super::helpers::resources::ResourceHelper;
use crate::theme::{self, Theme, playground_editor};
use anyhow::{Context, Result};
use log::{debug, warn};
use mdbook_core::config::HtmlConfig;
use mdbook_core::utils;
use mdbook_html::theme::{self, Theme, playground_editor};
use crate::renderer::html_handlebars::helpers::resources::ResourceHelper;
use std::borrow::Cow;
use std::collections::HashMap;
use std::fs::{self, File};
@@ -300,9 +298,9 @@ impl StaticFiles {
#[cfg(test)]
mod tests {
use super::*;
use crate::theme::Theme;
use mdbook_core::config::HtmlConfig;
use mdbook_core::utils::fs::write_file;
use mdbook_html::theme::Theme;
use tempfile::TempDir;
#[test]

View File

@@ -1,3 +1,6 @@
//! mdBook HTML renderer.
mod html_handlebars;
pub mod theme;
pub use html_handlebars::HtmlHandlebars;

View File

@@ -10,11 +10,14 @@ mod init;
pub use self::book::load_book;
pub use self::init::BookBuilder;
use crate::preprocess::{CmdPreprocessor, IndexPreprocessor, LinkPreprocessor};
use crate::renderer::{CmdRenderer, MarkdownRenderer};
use anyhow::{Context, Error, Result, bail};
use log::{debug, error, info, log_enabled, trace, warn};
pub use mdbook_core::book::{Book, BookItem, BookItems, Chapter, SectionNumber};
use mdbook_core::config::{Config, RustEdition};
use mdbook_core::utils;
use mdbook_html::HtmlHandlebars;
use mdbook_preprocessor::{Preprocessor, PreprocessorContext};
use mdbook_renderer::{RenderContext, Renderer};
pub use mdbook_summary::{Link, Summary, SummaryItem, parse_summary};
@@ -26,9 +29,6 @@ use tempfile::Builder as TempFileBuilder;
use toml::Value;
use topological_sort::TopologicalSort;
use crate::preprocess::{CmdPreprocessor, IndexPreprocessor, LinkPreprocessor};
use crate::renderer::{CmdRenderer, HtmlHandlebars, MarkdownRenderer};
/// The object used to manage and build a book.
pub struct MDBook {
/// The book's root directory.

View File

@@ -21,10 +21,8 @@ use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use toml::Value;
pub use self::html_handlebars::HtmlHandlebars;
pub use self::markdown_renderer::MarkdownRenderer;
mod html_handlebars;
mod markdown_renderer;
/// A generic renderer which will shell out to an arbitrary executable.

View File

@@ -12,7 +12,7 @@ fn basic_build() {
cmd.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the html backend
[TIMESTAMP] [INFO] (mdbook::renderer::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
[TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
"#]]);
});

View File

@@ -48,7 +48,7 @@ fn recursive_include() {
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [ERROR] (mdbook::preprocess::links): Stack depth exceeded in recursive.md. Check for cyclic includes
[TIMESTAMP] [INFO] (mdbook::book): Running the html backend
[TIMESTAMP] [INFO] (mdbook::renderer::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
[TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
"#]]);
})

View File

@@ -26,7 +26,7 @@ fn footnotes() {
[TIMESTAMP] [WARN] (mdbook_markdown): footnote `unused` in `<unknown>` is defined but not referenced
[TIMESTAMP] [WARN] (mdbook_markdown): footnote `multiple-definitions` in footnotes.md defined multiple times - not updating to new definition
[TIMESTAMP] [WARN] (mdbook_markdown): footnote `unused` in `footnotes.md` is defined but not referenced
[TIMESTAMP] [INFO] (mdbook::renderer::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
[TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
"#]]);
})

View File

@@ -49,7 +49,7 @@ fn nop_preprocessor() {
cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the html backend
[TIMESTAMP] [INFO] (mdbook::renderer::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
[TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
"#]]);
});

View File

@@ -26,7 +26,7 @@ fn empty_theme() {
cmd.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the html backend
[TIMESTAMP] [INFO] (mdbook::renderer::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
[TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
"#]]);
});
@@ -147,10 +147,10 @@ fn copy_fonts_false_no_theme() {
cmd.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the html backend
[TIMESTAMP] [WARN] (mdbook::renderer::html_handlebars::static_files): output.html.copy-fonts is deprecated.
[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::renderer::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
[TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
"#]]);
})
@@ -166,7 +166,7 @@ fn copy_fonts_false_with_empty_fonts_css() {
cmd.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the html backend
[TIMESTAMP] [INFO] (mdbook::renderer::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
[TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
"#]]);
})
@@ -182,7 +182,7 @@ fn copy_fonts_false_with_fonts_css() {
cmd.expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the html backend
[TIMESTAMP] [INFO] (mdbook::renderer::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
[TIMESTAMP] [INFO] (mdbook_html::html_handlebars::hbs_renderer): HTML book written to `[ROOT]/book`
"#]]);
})