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",
"mdbook-core",
"mdbook-preprocessor",
"mdbook-renderer",
"regex",
"serde_json",
"shlex",
"toml",
]
[[package]]

View File

@@ -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

View File

@@ -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)]

View File

@@ -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};

View File

@@ -1,3 +1,4 @@
//! High-level library for running mdBook.
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::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};

View File

@@ -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;

View File

@@ -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.
"#]]);
})