Finish moving builtin renderers to mdbook-driver

This commit is contained in:
Eric Huss 2025-07-21 21:12:43 -07:00
parent 9b27b14985
commit d758753551
8 changed files with 21 additions and 26 deletions

2
Cargo.lock generated
View file

@ -1316,9 +1316,11 @@ dependencies = [
"log", "log",
"mdbook-core", "mdbook-core",
"mdbook-preprocessor", "mdbook-preprocessor",
"mdbook-renderer",
"regex", "regex",
"serde_json", "serde_json",
"shlex", "shlex",
"toml",
] ]
[[package]] [[package]]

View file

@ -12,9 +12,11 @@ anyhow.workspace = true
log.workspace = true log.workspace = true
mdbook-core.workspace = true mdbook-core.workspace = true
mdbook-preprocessor.workspace = true mdbook-preprocessor.workspace = true
mdbook-renderer.workspace = true
regex.workspace = true regex.workspace = true
serde_json.workspace = true serde_json.workspace = true
shlex.workspace = true shlex.workspace = true
toml.workspace = true
[lints] [lints]
workspace = true workspace = true

View file

@ -1,8 +1,8 @@
use crate::book::BookItem;
use crate::renderer::{RenderContext, Renderer};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use log::trace; use log::trace;
use mdbook_core::book::BookItem;
use mdbook_core::utils; use mdbook_core::utils;
use mdbook_renderer::{RenderContext, Renderer};
use std::fs; use std::fs;
#[derive(Default)] #[derive(Default)]

View file

@ -1,15 +1,6 @@
//! `mdbook`'s low level rendering interface. //! Built-in renderers.
//! //!
//! # Note //! The HTML renderer can be found in the [`mdbook_html`] crate.
//!
//! 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
use anyhow::{Context, Result, bail}; use anyhow::{Context, Result, bail};
use log::{error, info, trace, warn}; use log::{error, info, trace, warn};

View file

@ -1,3 +1,4 @@
//! High-level library for running mdBook. //! High-level library for running mdBook.
pub mod builtin_preprocessors; pub mod builtin_preprocessors;
pub mod builtin_renderers;

View file

@ -10,13 +10,13 @@ mod init;
pub use self::book::load_book; pub use self::book::load_book;
pub use self::init::BookBuilder; pub use self::init::BookBuilder;
use crate::renderer::{CmdRenderer, MarkdownRenderer};
use anyhow::{Context, Error, Result, bail}; use anyhow::{Context, Error, Result, bail};
use log::{debug, error, info, log_enabled, trace, warn}; use log::{debug, error, info, log_enabled, trace, warn};
pub use mdbook_core::book::{Book, BookItem, BookItems, Chapter, SectionNumber}; pub use mdbook_core::book::{Book, BookItem, BookItems, Chapter, SectionNumber};
use mdbook_core::config::{Config, RustEdition}; use mdbook_core::config::{Config, RustEdition};
use mdbook_core::utils; use mdbook_core::utils;
use mdbook_driver::builtin_preprocessors::{CmdPreprocessor, IndexPreprocessor, LinkPreprocessor}; use mdbook_driver::builtin_preprocessors::{CmdPreprocessor, IndexPreprocessor, LinkPreprocessor};
use mdbook_driver::builtin_renderers::{CmdRenderer, MarkdownRenderer};
use mdbook_html::HtmlHandlebars; use mdbook_html::HtmlHandlebars;
use mdbook_preprocessor::{Preprocessor, PreprocessorContext}; use mdbook_preprocessor::{Preprocessor, PreprocessorContext};
use mdbook_renderer::{RenderContext, Renderer}; use mdbook_renderer::{RenderContext, Renderer};

View file

@ -81,7 +81,6 @@
//! [`Config`]: mdbook_core::config::Config //! [`Config`]: mdbook_core::config::Config
pub mod book; pub mod book;
pub mod renderer;
pub use crate::book::BookItem; pub use crate::book::BookItem;
pub use crate::book::MDBook; pub use crate::book::MDBook;

View file

@ -66,8 +66,8 @@ fn failing_command() {
.expect_stderr(str![[r#" .expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started [TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the failing backend [TIMESTAMP] [INFO] (mdbook::book): Running the failing backend
[TIMESTAMP] [INFO] (mdbook::renderer): Invoking the "failing" renderer [TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): Invoking the "failing" renderer
[TIMESTAMP] [ERROR] (mdbook::renderer): Renderer exited with non-zero return code. [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): Error: Rendering failed
[TIMESTAMP] [ERROR] (mdbook_core::utils): [TAB]Caused By: The "failing" renderer failed [TIMESTAMP] [ERROR] (mdbook_core::utils): [TAB]Caused By: The "failing" renderer failed
@ -84,8 +84,8 @@ fn missing_renderer() {
.expect_stderr(str![[r#" .expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started [TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the missing backend [TIMESTAMP] [INFO] (mdbook::book): Running the missing backend
[TIMESTAMP] [INFO] (mdbook::renderer): Invoking the "missing" renderer [TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): 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] [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): Error: Rendering failed
[TIMESTAMP] [ERROR] (mdbook_core::utils): [TAB]Caused By: Unable to start the backend [TIMESTAMP] [ERROR] (mdbook_core::utils): [TAB]Caused By: Unable to start the backend
[TIMESTAMP] [ERROR] (mdbook_core::utils): [TAB]Caused By: [NOT_FOUND] [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#" cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started [TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the missing backend [TIMESTAMP] [INFO] (mdbook::book): Running the missing backend
[TIMESTAMP] [INFO] (mdbook::renderer): Invoking the "missing" renderer [TIMESTAMP] [INFO] (mdbook_driver::builtin_renderers): Invoking the "missing" renderer
[TIMESTAMP] [WARN] (mdbook::renderer): The command `trduyvbhijnorgevfuhn` for backend `missing` was not found, but was marked as optional. [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#" .expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started [TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the arguments backend [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#" cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started [TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the cat-to-file backend [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#" cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started [TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the myrenderer backend [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#" cmd.expect_stdout(str![[""]]).expect_stderr(str![[r#"
[TIMESTAMP] [INFO] (mdbook::book): Book building has started [TIMESTAMP] [INFO] (mdbook::book): Book building has started
[TIMESTAMP] [INFO] (mdbook::book): Running the myrenderer backend [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
[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] [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.
"#]]); "#]]);
}) })