Skip to content

Commit f5fc544

Browse files
committed
Finish moving built-in preprocessors to mdbook-driver
1 parent 6aac696 commit f5fc544

File tree

12 files changed

+34
-11
lines changed

12 files changed

+34
-11
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ regex = "1.11.1"
4141
serde = { version = "1.0.219", features = ["derive"] }
4242
serde_json = "1.0.140"
4343
sha2 = "0.10.9"
44+
shlex = "1.3.0"
4445
tempfile = "3.20.0"
4546
toml = "0.5.11" # Do not update, see https://github.com/rust-lang/mdBook/issues/2037
4647

@@ -70,6 +71,7 @@ clap_complete = "4.3.2"
7071
env_logger = "0.11.1"
7172
log.workspace = true
7273
mdbook-core.workspace = true
74+
mdbook-driver.workspace = true
7375
mdbook-html.workspace = true
7476
mdbook-markdown.workspace = true
7577
mdbook-preprocessor.workspace = true
@@ -81,7 +83,7 @@ pulldown-cmark.workspace = true
8183
regex.workspace = true
8284
serde.workspace = true
8385
serde_json.workspace = true
84-
shlex = "1.3.0"
86+
shlex.workspace = true
8587
tempfile.workspace = true
8688
toml.workspace = true
8789
topological-sort = "0.2.2"

crates/mdbook-driver/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ repository.workspace = true
88
rust-version.workspace = true
99

1010
[dependencies]
11+
anyhow.workspace = true
12+
log.workspace = true
13+
mdbook-core.workspace = true
14+
mdbook-preprocessor.workspace = true
15+
regex.workspace = true
16+
serde_json.workspace = true
17+
shlex.workspace = true
1118

1219
[lints]
1320
workspace = true

crates/mdbook-driver/src/builtin_preprocessors/cmd.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::book::Book;
21
use anyhow::{Context, Result, bail, ensure};
32
use log::{debug, trace, warn};
3+
use mdbook_core::book::Book;
44
use mdbook_preprocessor::{Preprocessor, PreprocessorContext};
55
use shlex::Shlex;
66
use std::io::{self, Write};
@@ -170,6 +170,7 @@ impl Preprocessor for CmdPreprocessor {
170170
}
171171
}
172172

173+
#[cfg(false)] // Needs to wait for MDBook transfer
173174
#[cfg(test)]
174175
mod tests {
175176
use super::*;

crates/mdbook-driver/src/builtin_preprocessors/index.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::book::{Book, BookItem};
21
use anyhow::Result;
32
use log::warn;
3+
use mdbook_core::book::{Book, BookItem};
44
use mdbook_preprocessor::{Preprocessor, PreprocessorContext};
55
use regex::Regex;
66
use std::{path::Path, sync::LazyLock};
@@ -11,7 +11,8 @@ use std::{path::Path, sync::LazyLock};
1111
pub struct IndexPreprocessor;
1212

1313
impl IndexPreprocessor {
14-
pub(crate) const NAME: &'static str = "index";
14+
/// Name of this preprocessor.
15+
pub const NAME: &'static str = "index";
1516

1617
/// Create a new `IndexPreprocessor`.
1718
pub fn new() -> Self {

crates/mdbook-driver/src/builtin_preprocessors/links.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use crate::book::{Book, BookItem};
21
use anyhow::{Context, Result};
32
use log::{error, warn};
3+
use mdbook_core::book::{Book, BookItem};
44
use mdbook_core::utils::{
55
take_anchored_lines, take_lines, take_rustdoc_include_anchored_lines,
66
take_rustdoc_include_lines,
@@ -29,7 +29,8 @@ const MAX_LINK_NESTED_DEPTH: usize = 10;
2929
pub struct LinkPreprocessor;
3030

3131
impl LinkPreprocessor {
32-
pub(crate) const NAME: &'static str = "links";
32+
/// Name of this preprocessor.
33+
pub const NAME: &'static str = "links";
3334

3435
/// Create a new `LinkPreprocessor`.
3536
pub fn new() -> Self {

crates/mdbook-driver/src/builtin_preprocessors/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Book preprocessing.
1+
//! Built-in preprocessors.
22
33
pub use self::cmd::CmdPreprocessor;
44
pub use self::index::IndexPreprocessor;

crates/mdbook-driver/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
//! High-level library for running mdBook.
2+
3+
pub mod builtin_preprocessors;

src/book/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ mod init;
1010

1111
pub use self::book::load_book;
1212
pub use self::init::BookBuilder;
13-
use crate::preprocess::{CmdPreprocessor, IndexPreprocessor, LinkPreprocessor};
1413
use crate::renderer::{CmdRenderer, MarkdownRenderer};
1514
use anyhow::{Context, Error, Result, bail};
1615
use log::{debug, error, info, log_enabled, trace, warn};
1716
pub use mdbook_core::book::{Book, BookItem, BookItems, Chapter, SectionNumber};
1817
use mdbook_core::config::{Config, RustEdition};
1918
use mdbook_core::utils;
19+
use mdbook_driver::builtin_preprocessors::{CmdPreprocessor, IndexPreprocessor, LinkPreprocessor};
2020
use mdbook_html::HtmlHandlebars;
2121
use mdbook_preprocessor::{Preprocessor, PreprocessorContext};
2222
use mdbook_renderer::{RenderContext, Renderer};

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@
8181
//! [`Config`]: mdbook_core::config::Config
8282
8383
pub mod book;
84-
pub mod preprocess;
8584
pub mod renderer;
8685

8786
pub use crate::book::BookItem;

0 commit comments

Comments
 (0)