Skip to content

Commit 7eccd1d

Browse files
committed
Finish move of hbs_renderer to mdbook-html
This updates everything for the move of hbs_renderer to mdbook-html.
1 parent 06324d8 commit 7eccd1d

File tree

15 files changed

+76
-64
lines changed

15 files changed

+76
-64
lines changed

Cargo.lock

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ repository = "https://github.com/rust-lang/mdBook"
2121
rust-version = "1.85.0" # Keep in sync with installation.md and .github/workflows/main.yml
2222

2323
[workspace.dependencies]
24+
ammonia = "4.1.1"
2425
anyhow = "1.0.98"
26+
elasticlunr-rs = "3.0.2"
27+
handlebars = "6.3.2"
28+
hex = "0.4.3"
2529
log = "0.4.27"
2630
mdbook-core = { path = "crates/mdbook-core" }
2731
mdbook-html = { path = "crates/mdbook-html" }
@@ -30,10 +34,12 @@ mdbook-preprocessor = { path = "crates/mdbook-preprocessor" }
3034
mdbook-renderer = { path = "crates/mdbook-renderer" }
3135
mdbook-summary = { path = "crates/mdbook-summary" }
3236
memchr = "2.7.5"
37+
pretty_assertions = "1.4.1"
3338
pulldown-cmark = { version = "0.10.3", default-features = false, features = ["html"] } # Do not update, part of the public api.
3439
regex = "1.11.1"
3540
serde = { version = "1.0.219", features = ["derive"] }
3641
serde_json = "1.0.140"
42+
sha2 = "0.10.9"
3743
tempfile = "3.20.0"
3844
toml = "0.5.11" # Do not update, see https://github.com/rust-lang/mdBook/issues/2037
3945

@@ -61,8 +67,6 @@ chrono = { version = "0.4.24", default-features = false, features = ["clock"] }
6167
clap = { version = "4.3.12", features = ["cargo", "wrap_help"] }
6268
clap_complete = "4.3.2"
6369
env_logger = "0.11.1"
64-
handlebars = "6.0"
65-
hex = "0.4.3"
6670
log.workspace = true
6771
mdbook-core.workspace = true
6872
mdbook-html.workspace = true
@@ -76,7 +80,6 @@ pulldown-cmark.workspace = true
7680
regex.workspace = true
7781
serde.workspace = true
7882
serde_json.workspace = true
79-
sha2 = "0.10.8"
8083
shlex = "1.3.0"
8184
tempfile.workspace = true
8285
toml.workspace = true
@@ -95,22 +98,17 @@ tokio = { version = "1.43.1", features = ["macros", "rt-multi-thread"], optional
9598
axum = { version = "0.8.0", features = ["ws"], optional = true }
9699
tower-http = { version = "0.6.0", features = ["fs", "trace"], optional = true }
97100

98-
# Search feature
99-
elasticlunr-rs = { version = "3.0.2", optional = true }
100-
ammonia = { version = "4.0.0", optional = true }
101-
102101
[dev-dependencies]
103102
select = "0.6.0"
104103
semver = "1.0.17"
105104
snapbox = { version = "0.6.21", features = ["diff", "dir", "term-svg", "regex", "json"] }
106-
pretty_assertions = "1.3.0"
107105
walkdir = "2.3.3"
108106

109107
[features]
110108
default = ["watch", "serve", "search"]
111109
watch = ["dep:notify", "dep:notify-debouncer-mini", "dep:ignore", "dep:pathdiff", "dep:walkdir"]
112110
serve = ["dep:futures-util", "dep:tokio", "dep:axum", "dep:tower-http"]
113-
search = ["dep:elasticlunr-rs", "dep:ammonia", "mdbook-html/search"]
111+
search = ["mdbook-html/search"]
114112

115113
[[bin]]
116114
doc = false

crates/mdbook-html/Cargo.toml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,28 @@ repository.workspace = true
88
rust-version.workspace = true
99

1010
[dependencies]
11+
ammonia = { workspace = true, optional = true }
1112
anyhow.workspace = true
13+
elasticlunr-rs = { workspace = true, optional = true }
14+
handlebars.workspace = true
15+
hex.workspace = true
1216
log.workspace = true
17+
mdbook-core.workspace = true
18+
mdbook-markdown.workspace = true
19+
mdbook-renderer.workspace = true
20+
pulldown-cmark.workspace = true
21+
regex.workspace = true
22+
serde.workspace = true
23+
serde_json.workspace = true
24+
sha2.workspace = true
1325

1426
[dev-dependencies]
27+
pretty_assertions.workspace = true
1528
tempfile.workspace = true
29+
toml.workspace = true
1630

1731
[lints]
1832
workspace = true
1933

2034
[features]
21-
search = []
35+
search = ["dep:ammonia", "dep:elasticlunr-rs"]

crates/mdbook-html/src/html_handlebars/hbs_renderer.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
use crate::book::{Book, BookItem};
2-
use crate::renderer::html_handlebars::StaticFiles;
3-
use crate::renderer::html_handlebars::helpers;
4-
use crate::renderer::{RenderContext, Renderer};
5-
6-
use std::borrow::Cow;
7-
use std::collections::BTreeMap;
8-
use std::collections::HashMap;
9-
use std::fs::{self, File};
10-
use std::path::{Path, PathBuf};
11-
use std::sync::LazyLock;
12-
1+
use super::helpers;
2+
use super::static_files::StaticFiles;
3+
use crate::theme::Theme;
134
use anyhow::{Context, Result, bail};
145
use handlebars::Handlebars;
156
use log::{debug, info, trace, warn};
7+
use mdbook_core::book::{Book, BookItem};
168
use mdbook_core::config::{BookConfig, Code, Config, HtmlConfig, Playground, RustEdition};
179
use mdbook_core::utils;
1810
use mdbook_core::utils::fs::get_404_output_file;
19-
use mdbook_html::theme::Theme;
2011
use mdbook_markdown::{render_markdown, render_markdown_with_path};
21-
12+
use mdbook_renderer::{RenderContext, Renderer};
2213
use regex::{Captures, Regex};
2314
use serde_json::json;
15+
use std::borrow::Cow;
16+
use std::collections::BTreeMap;
17+
use std::collections::HashMap;
18+
use std::fs::{self, File};
19+
use std::path::{Path, PathBuf};
20+
use std::sync::LazyLock;
2421

2522
/// The HTML renderer for mdBook.
2623
#[derive(Default)]
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
pub use self::hbs_renderer::HtmlHandlebars;
2-
pub use self::static_files::StaticFiles;
3-
41
mod hbs_renderer;
52
mod helpers;
6-
mod static_files;
7-
83
#[cfg(feature = "search")]
94
mod search;
5+
mod static_files;
6+
7+
pub use self::hbs_renderer::HtmlHandlebars;

crates/mdbook-html/src/html_handlebars/search.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
use std::borrow::Cow;
2-
use std::collections::{HashMap, HashSet};
3-
use std::path::{Path, PathBuf};
4-
use std::sync::LazyLock;
5-
1+
use super::static_files::StaticFiles;
2+
use crate::theme::searcher;
63
use anyhow::{Context, Result, bail};
74
use elasticlunr::{Index, IndexBuilder};
85
use log::{debug, warn};
6+
use mdbook_core::book::{Book, BookItem, Chapter};
97
use mdbook_core::config::{Search, SearchChapterSettings};
108
use mdbook_core::utils;
11-
use mdbook_html::theme::searcher;
129
use mdbook_markdown::new_cmark_parser;
1310
use pulldown_cmark::*;
1411
use serde::Serialize;
15-
16-
use crate::book::{Book, BookItem, Chapter};
17-
use crate::renderer::html_handlebars::StaticFiles;
12+
use std::borrow::Cow;
13+
use std::collections::{HashMap, HashSet};
14+
use std::path::{Path, PathBuf};
15+
use std::sync::LazyLock;
1816

1917
const MAX_WORD_LENGTH_TO_INDEX: usize = 80;
2018

@@ -394,7 +392,7 @@ fn chapter_settings_priority() {
394392
"cli/inner" = { enable = true }
395393
"foo" = {} # Just to make sure empty table is allowed.
396394
"#;
397-
let cfg: crate::Config = toml::from_str(cfg).unwrap();
395+
let cfg: mdbook_core::config::Config = toml::from_str(cfg).unwrap();
398396
let html = cfg.html_config().unwrap();
399397
let chapter_configs = sort_search_config(&html.search.unwrap().chapter);
400398
for (path, enable) in [

crates/mdbook-html/src/html_handlebars/static_files.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
//! Support for writing static files.
22
3+
use super::helpers::resources::ResourceHelper;
4+
use crate::theme::{self, Theme, playground_editor};
35
use anyhow::{Context, Result};
46
use log::{debug, warn};
57
use mdbook_core::config::HtmlConfig;
68
use mdbook_core::utils;
7-
use mdbook_html::theme::{self, Theme, playground_editor};
8-
9-
use crate::renderer::html_handlebars::helpers::resources::ResourceHelper;
10-
119
use std::borrow::Cow;
1210
use std::collections::HashMap;
1311
use std::fs::{self, File};
@@ -300,9 +298,9 @@ impl StaticFiles {
300298
#[cfg(test)]
301299
mod tests {
302300
use super::*;
301+
use crate::theme::Theme;
303302
use mdbook_core::config::HtmlConfig;
304303
use mdbook_core::utils::fs::write_file;
305-
use mdbook_html::theme::Theme;
306304
use tempfile::TempDir;
307305

308306
#[test]

crates/mdbook-html/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
//! mdBook HTML renderer.
22
3+
mod html_handlebars;
34
pub mod theme;
5+
6+
pub use html_handlebars::HtmlHandlebars;

src/book/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ mod init;
1010

1111
pub use self::book::load_book;
1212
pub use self::init::BookBuilder;
13+
use crate::preprocess::{CmdPreprocessor, IndexPreprocessor, LinkPreprocessor};
14+
use crate::renderer::{CmdRenderer, MarkdownRenderer};
1315
use anyhow::{Context, Error, Result, bail};
1416
use log::{debug, error, info, log_enabled, trace, warn};
1517
pub use mdbook_core::book::{Book, BookItem, BookItems, Chapter, SectionNumber};
1618
use mdbook_core::config::{Config, RustEdition};
1719
use mdbook_core::utils;
20+
use mdbook_html::HtmlHandlebars;
1821
use mdbook_preprocessor::{Preprocessor, PreprocessorContext};
1922
use mdbook_renderer::{RenderContext, Renderer};
2023
pub use mdbook_summary::{Link, Summary, SummaryItem, parse_summary};
@@ -26,9 +29,6 @@ use tempfile::Builder as TempFileBuilder;
2629
use toml::Value;
2730
use topological_sort::TopologicalSort;
2831

29-
use crate::preprocess::{CmdPreprocessor, IndexPreprocessor, LinkPreprocessor};
30-
use crate::renderer::{CmdRenderer, HtmlHandlebars, MarkdownRenderer};
31-
3232
/// The object used to manage and build a book.
3333
pub struct MDBook {
3434
/// The book's root directory.

src/renderer/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ use std::path::{Path, PathBuf};
2121
use std::process::{Command, Stdio};
2222
use toml::Value;
2323

24-
pub use self::html_handlebars::HtmlHandlebars;
2524
pub use self::markdown_renderer::MarkdownRenderer;
2625

27-
mod html_handlebars;
2826
mod markdown_renderer;
2927

3028
/// A generic renderer which will shell out to an arbitrary executable.

0 commit comments

Comments
 (0)