From d7587535515e7dedc93e49ca2cf9356ec315c574 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 21 Jul 2025 21:12:43 -0700 Subject: [PATCH] Finish moving builtin renderers to mdbook-driver --- Cargo.lock | 2 ++ crates/mdbook-driver/Cargo.toml | 2 ++ .../builtin_renderers/markdown_renderer.rs | 4 ++-- .../src/builtin_renderers/mod.rs | 13 ++--------- crates/mdbook-driver/src/lib.rs | 1 + src/book/mod.rs | 2 +- src/lib.rs | 1 - tests/testsuite/renderer.rs | 22 +++++++++---------- 8 files changed, 21 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8c5e4328..b66a7116 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1316,9 +1316,11 @@ dependencies = [ "log", "mdbook-core", "mdbook-preprocessor", + "mdbook-renderer", "regex", "serde_json", "shlex", + "toml", ] [[package]] diff --git a/crates/mdbook-driver/Cargo.toml b/crates/mdbook-driver/Cargo.toml index 8417ed15..a6b788fa 100644 --- a/crates/mdbook-driver/Cargo.toml +++ b/crates/mdbook-driver/Cargo.toml @@ -12,9 +12,11 @@ anyhow.workspace = true log.workspace = true mdbook-core.workspace = true mdbook-preprocessor.workspace = true +mdbook-renderer.workspace = true regex.workspace = true serde_json.workspace = true shlex.workspace = true +toml.workspace = true [lints] workspace = true diff --git a/crates/mdbook-driver/src/builtin_renderers/markdown_renderer.rs b/crates/mdbook-driver/src/builtin_renderers/markdown_renderer.rs index 638b21f0..5255bc80 100644 --- a/crates/mdbook-driver/src/builtin_renderers/markdown_renderer.rs +++ b/crates/mdbook-driver/src/builtin_renderers/markdown_renderer.rs @@ -1,8 +1,8 @@ -use crate::book::BookItem; -use crate::renderer::{RenderContext, Renderer}; use anyhow::{Context, Result}; use log::trace; +use mdbook_core::book::BookItem; use mdbook_core::utils; +use mdbook_renderer::{RenderContext, Renderer}; use std::fs; #[derive(Default)] diff --git a/crates/mdbook-driver/src/builtin_renderers/mod.rs b/crates/mdbook-driver/src/builtin_renderers/mod.rs index e3503779..0218a62d 100644 --- a/crates/mdbook-driver/src/builtin_renderers/mod.rs +++ b/crates/mdbook-driver/src/builtin_renderers/mod.rs @@ -1,15 +1,6 @@ -//! `mdbook`'s low level rendering interface. +//! Built-in renderers. //! -//! # Note -//! -//! You usually don't need to work with this module directly. If you want to -//! implement your own backend, then check out the [For Developers] section of -//! the user guide. -//! -//! The definition for [RenderContext] may be useful though. -//! -//! [For Developers]: https://rust-lang.github.io/mdBook/for_developers/index.html -//! [RenderContext]: struct.RenderContext.html +//! The HTML renderer can be found in the [`mdbook_html`] crate. use anyhow::{Context, Result, bail}; use log::{error, info, trace, warn}; diff --git a/crates/mdbook-driver/src/lib.rs b/crates/mdbook-driver/src/lib.rs index 08f7e17b..b359b576 100644 --- a/crates/mdbook-driver/src/lib.rs +++ b/crates/mdbook-driver/src/lib.rs @@ -1,3 +1,4 @@ //! High-level library for running mdBook. pub mod builtin_preprocessors; +pub mod builtin_renderers; diff --git a/src/book/mod.rs b/src/book/mod.rs index c650d4d2..df9b8fac 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -10,13 +10,13 @@ mod init; pub use self::book::load_book; pub use self::init::BookBuilder; -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_driver::builtin_preprocessors::{CmdPreprocessor, IndexPreprocessor, LinkPreprocessor}; +use mdbook_driver::builtin_renderers::{CmdRenderer, MarkdownRenderer}; use mdbook_html::HtmlHandlebars; use mdbook_preprocessor::{Preprocessor, PreprocessorContext}; use mdbook_renderer::{RenderContext, Renderer}; diff --git a/src/lib.rs b/src/lib.rs index 5b5c7a64..0d534e8d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,7 +81,6 @@ //! [`Config`]: mdbook_core::config::Config pub mod book; -pub mod renderer; pub use crate::book::BookItem; pub use crate::book::MDBook; diff --git a/tests/testsuite/renderer.rs b/tests/testsuite/renderer.rs index abf45502..5b49d759 100644 --- a/tests/testsuite/renderer.rs +++ b/tests/testsuite/renderer.rs @@ -66,8 +66,8 @@ fn failing_command() { .expect_stderr(str![[r#" [TIMESTAMP] [INFO] (mdbook::book): Book building has started [TIMESTAMP] [INFO] (mdbook::book): Running the failing backend -[TIMESTAMP] [INFO] (mdbook::renderer): Invoking the "failing" renderer -[TIMESTAMP] [ERROR] (mdbook::renderer): Renderer exited with non-zero return code. +[TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): Invoking the "failing" renderer +[TIMESTAMP] [ERROR] (mdbook_driver::builtin_renderers): Renderer exited with non-zero return code. [TIMESTAMP] [ERROR] (mdbook_core::utils): Error: Rendering failed [TIMESTAMP] [ERROR] (mdbook_core::utils): [TAB]Caused By: The "failing" renderer failed @@ -84,8 +84,8 @@ fn missing_renderer() { .expect_stderr(str![[r#" [TIMESTAMP] [INFO] (mdbook::book): Book building has started [TIMESTAMP] [INFO] (mdbook::book): Running the missing backend -[TIMESTAMP] [INFO] (mdbook::renderer): Invoking the "missing" renderer -[TIMESTAMP] [ERROR] (mdbook::renderer): The command `trduyvbhijnorgevfuhn` wasn't found, is the "missing" backend installed? If you want to ignore this error when the "missing" backend is not installed, set `optional = true` in the `[output.missing]` section of the book.toml configuration file. +[TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): Invoking the "missing" renderer +[TIMESTAMP] [ERROR] (mdbook_driver::builtin_renderers): The command `trduyvbhijnorgevfuhn` wasn't found, is the "missing" backend installed? If you want to ignore this error when the "missing" backend is not installed, set `optional = true` in the `[output.missing]` section of the book.toml configuration file. [TIMESTAMP] [ERROR] (mdbook_core::utils): Error: Rendering failed [TIMESTAMP] [ERROR] (mdbook_core::utils): [TAB]Caused By: Unable to start the backend [TIMESTAMP] [ERROR] (mdbook_core::utils): [TAB]Caused By: [NOT_FOUND] @@ -101,8 +101,8 @@ fn missing_optional_not_fatal() { cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#" [TIMESTAMP] [INFO] (mdbook::book): Book building has started [TIMESTAMP] [INFO] (mdbook::book): Running the missing backend -[TIMESTAMP] [INFO] (mdbook::renderer): Invoking the "missing" renderer -[TIMESTAMP] [WARN] (mdbook::renderer): The command `trduyvbhijnorgevfuhn` for backend `missing` was not found, but was marked as optional. +[TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): Invoking the "missing" renderer +[TIMESTAMP] [WARN] (mdbook_driver::builtin_renderers): The command `trduyvbhijnorgevfuhn` for backend `missing` was not found, but was marked as optional. "#]]); }); @@ -133,7 +133,7 @@ Hello World! .expect_stderr(str![[r#" [TIMESTAMP] [INFO] (mdbook::book): Book building has started [TIMESTAMP] [INFO] (mdbook::book): Running the arguments backend -[TIMESTAMP] [INFO] (mdbook::renderer): Invoking the "arguments" renderer +[TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): Invoking the "arguments" renderer "#]]); }); @@ -158,7 +158,7 @@ fn backends_receive_render_context_via_stdin() { cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#" [TIMESTAMP] [INFO] (mdbook::book): Book building has started [TIMESTAMP] [INFO] (mdbook::book): Running the cat-to-file backend -[TIMESTAMP] [INFO] (mdbook::renderer): Invoking the "cat-to-file" renderer +[TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): Invoking the "cat-to-file" renderer "#]]); }) @@ -236,7 +236,7 @@ fn legacy_relative_command_path() { cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#" [TIMESTAMP] [INFO] (mdbook::book): Book building has started [TIMESTAMP] [INFO] (mdbook::book): Running the myrenderer backend -[TIMESTAMP] [INFO] (mdbook::renderer): Invoking the "myrenderer" renderer +[TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): Invoking the "myrenderer" renderer "#]]); }) @@ -255,8 +255,8 @@ fn legacy_relative_command_path() { cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#" [TIMESTAMP] [INFO] (mdbook::book): Book building has started [TIMESTAMP] [INFO] (mdbook::book): Running the myrenderer backend -[TIMESTAMP] [INFO] (mdbook::renderer): Invoking the "myrenderer" renderer -[TIMESTAMP] [WARN] (mdbook::renderer): Renderer command `../renderers/myrenderer[EXE]` uses a path relative to the renderer output directory `[ROOT]/book`. This was previously accepted, but has been deprecated. Relative executable paths should be relative to the book root. +[TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): Invoking the "myrenderer" renderer +[TIMESTAMP] [WARN] (mdbook_driver::builtin_renderers): Renderer command `../renderers/myrenderer[EXE]` uses a path relative to the renderer output directory `[ROOT]/book`. This was previously accepted, but has been deprecated. Relative executable paths should be relative to the book root. "#]]); })