Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Upgrade to mdbook 0.5.1 (breaking)
Fixes: #134
  • Loading branch information
michalfita committed Nov 21, 2025
commit 94eff92512c7de49b2bd9ef42a6a64c726cdf3a1
561 changes: 397 additions & 164 deletions Cargo.lock

Large diffs are not rendered by default.

30 changes: 18 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ documentation = "https://docs.rs/mdbook-epub"
keywords = ["epub", "mdbook", "documentation", "markdown"]
categories = ["command-line-interface", "development-tools"]
edition = "2024"
rust-version = "1.85"
rust-version = "1.88"

[package.metadata.release]
sign-commit = true
Expand All @@ -23,29 +23,35 @@ name = "mdbook-epub"
doc = false

[dependencies]
clap = { version = "4.5", default-features = false, features = ["derive"] }
clap = { version = "4.5", default-features = false, features = [
"derive",
"std",
] }
epub-builder = "0.8"
thiserror = "2.0"
pulldown-cmark = "0.10.0"
pulldown-cmark = "0.13.0"
semver = "1.0"
serde = { version = "1.0.163", features = ["derive"] }
serde = { version = "1.0.228", features = ["derive"] }
serde_derive = "1.0"
serde_json = "1.0.96"
serde_json = "1.0.145"
mime_guess = "2.0"
env_logger = "0.11.1"
log = "0.4.17"
mdbook = { version = "0.4.47", default-features = false }
handlebars = "6.0"
toml = "0.5.11" # downgraded due to parent 'mdbook' dependency and error there
env_logger = "0.11.8"
log = "0.4.28"
mdbook-core = { version = "0.5.1", default-features = false } # I'm kinda anxious about it as they say it's for internal use, examples still outdated
mdbook-driver = { version = "0.5.1", default-features = false } # Because we support standalone rendering...
mdbook-renderer = { version = "0.5.1", default-features = false }

handlebars = "6.3"
toml = "0.9.8"
html_parser = "0.7.0"
url = "2.5"
ureq = "3.0"
ureq = "3.1"
infer = "0.19"
urlencoding = "2.1"
const_format = "0.2"

[dev-dependencies]
tempfile = "3.19"
tempfile = "3.23"
epub = "2.1"
serial_test = "3.2"
mockall = "0.13"
Expand Down
9 changes: 5 additions & 4 deletions src/bin/mdbook-epub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use std::path::PathBuf;
use std::process;

use ::env_logger;
use ::mdbook;
use ::serde_json;
use clap::Parser;
use mdbook::renderer::RenderContext;
use mdbook::MDBook;
use mdbook_driver::MDBook;
use mdbook_renderer::RenderContext;

use ::mdbook_epub;
use mdbook_epub::errors::Error;
Expand Down Expand Up @@ -47,7 +46,9 @@ fn run(args: &Args) -> Result<(), Error> {
debug!("EPUB book config is : {:?}", md.config);
RenderContext::new(md.root, md.book, md.config, destination)
} else {
println!("Running mdbook-epub as plugin waiting on the STDIN input. If you wanted to process the files in the current folder, use the -s flag from documentation, See: mdbook-epub --help");
println!(
"Running mdbook-epub as plugin waiting on the STDIN input. If you wanted to process the files in the current folder, use the -s flag from documentation, See: mdbook-epub --help"
);
serde_json::from_reader(io::stdin()).map_err(|_| Error::RenderContext)?
};
debug!("calling the main code for epub creation");
Expand Down
10 changes: 4 additions & 6 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::Error;
use mdbook::renderer::RenderContext;
use mdbook_renderer::RenderContext;
use std::path::PathBuf;

pub const DEFAULT_TEMPLATE: &str = include_str!("index.hbs");
Expand Down Expand Up @@ -34,10 +34,8 @@ impl Config {
/// Get the `output.epub` table from the provided `book.toml` config,
/// falling back to the default if
pub fn from_render_context(ctx: &RenderContext) -> Result<Config, Error> {
match ctx.config.get("output.epub") {
Some(table) => {
let mut cfg: Config = table.clone().try_into()?;

match ctx.config.get::<Config>("output.epub")? {
Some(mut cfg) => {
// make sure we update the `index_template` to make it relative
// to the book root
if let Some(template_file) = cfg.index_template.take() {
Expand Down Expand Up @@ -100,7 +98,7 @@ mod tests {

fn ctx_with_template(source: &str, destination: &Path) -> serde_json::Value {
json!({
"version": mdbook::MDBOOK_VERSION,
"version": mdbook_core::MDBOOK_VERSION,
"root": "tests/long_book_example",
"book": {"sections": [], "__non_exhaustive": null},
"config": {
Expand Down
2 changes: 1 addition & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub enum Error {
AssetOutsideSrcDir(#[from] std::path::StripPrefixError),

#[error(transparent)]
Book(#[from] mdbook::errors::Error),
Book(#[from] mdbook_core::errors::Error),
#[error(transparent)]
Semver(#[from] semver::Error),
#[error(transparent)]
Expand Down
12 changes: 6 additions & 6 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use crate::validation::validate_config_epub_version;
use crate::{Error, utils};
use epub_builder::{EpubBuilder, EpubContent, ZipLibrary};
use handlebars::{Handlebars, RenderError, RenderErrorReason};
use mdbook::book::{BookItem, Chapter};
use mdbook::renderer::RenderContext;
use mdbook_core::book::{BookItem, Chapter};
use mdbook_renderer::RenderContext;
use pulldown_cmark::html;
use std::collections::HashSet;
use std::{
Expand Down Expand Up @@ -135,7 +135,7 @@ impl<'a> Generator<'a> {
info!("3.1 Generate chapters == ");

let mut added_count = 0;
for (idx, item) in self.ctx.book.sections.iter().enumerate() {
for (idx, item) in self.ctx.book.iter().enumerate() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.ctx.book.iter() - now returns Items + SubItems as one long list.
So that code is ok.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But code at the end of method
fn add_chapter(&mut self, ch: &Chapter, is_first: Option<bool>) -> Result<(), Error>

that block

// second pass to actually add the sub-chapters
        for sub_item in &ch.sub_items {
            if let BookItem::Chapter(ref sub_ch) = *sub_item {
                trace!("add sub-item = {:?}", sub_ch.name);
                self.add_chapter(sub_ch, None)?;
            }
        }

Should be removed because it causes duplicate Chapter is added to book.

let is_first = idx == 0;
if let BookItem::Chapter(ref ch) = *item {
trace!("Adding chapter \"{}\"", ch);
Expand Down Expand Up @@ -650,7 +650,7 @@ mod tests {
let pat = |heading, prefix| {
format!("<h1>{heading}</h1>\n<p><img src=\"{prefix}78d88324ed4ac3bf.svg\"")
};
if let BookItem::Chapter(ref ch) = ctx.book.sections[0] {
if let BookItem::Chapter(ref ch) = ctx.book.items[0] {
let rendered: String = g.render_chapter(ch).unwrap();
debug!("rendered ===\n{}", &rendered);
assert!(rendered.contains(&pat("Chapter 1", "../")));
Expand All @@ -665,7 +665,7 @@ mod tests {
} else {
panic!();
}
if let BookItem::Chapter(ref ch) = ctx.book.sections[1] {
if let BookItem::Chapter(ref ch) = ctx.book.items[1] {
let rendered: String = g.render_chapter(ch).unwrap();
assert!(rendered.contains(&pat("Chapter 2", "")));
} else {
Expand All @@ -691,7 +691,7 @@ mod tests {

fn ctx_with_template(content: &str, source: &str, destination: &Path) -> serde_json::Value {
json!({
"version": mdbook::MDBOOK_VERSION,
"version": mdbook_core::MDBOOK_VERSION,
"root": "tests/long_book_example",
"book": {"sections": [{
"Chapter": {
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ extern crate serde_json;
use std::fs::{File, create_dir_all};
use std::path::{Path, PathBuf};

use ::mdbook;
use ::mdbook_core;
use ::semver;
use ::thiserror::Error;
use mdbook::config::Config as MdConfig;
use mdbook::renderer::RenderContext;
use mdbook_core::config::Config as MdConfig;
use mdbook_renderer::RenderContext;
use semver::{Version, VersionReq};

use errors::Error;
Expand All @@ -35,7 +35,7 @@ mod validation;
pub const DEFAULT_CSS: &str = include_str!("master.css");

/// The exact version of `mdbook` this crate is compiled against.
pub const MDBOOK_VERSION: &str = mdbook::MDBOOK_VERSION;
pub const MDBOOK_VERSION: &str = mdbook_core::MDBOOK_VERSION;

/// Check that the version of `mdbook` we're called by is compatible with this
/// backend.
Expand Down
10 changes: 5 additions & 5 deletions src/resources/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::path::MAIN_SEPARATOR_STR;

use const_format::concatcp;
use html_parser::{Dom, Element, Node};
use mdbook::book::BookItem;
use mdbook::renderer::RenderContext;
use mdbook_core::book::BookItem;
use mdbook_renderer::RenderContext;
use pulldown_cmark::{Event, Tag};
use url::Url;

Expand Down Expand Up @@ -35,7 +35,7 @@ pub(crate) fn find(ctx: &RenderContext) -> Result<HashMap<String, Asset>, Error>

debug!(
"Start iteration over a [{:?}] sections in src_dir = {:?}",
ctx.book.sections.len(),
ctx.book.items.len(),
src_dir
);
for section in ctx.book.iter() {
Expand Down Expand Up @@ -396,9 +396,9 @@ mod tests {
fn ctx_with_chapters(
chapters: &Value,
destination: &str,
) -> Result<RenderContext, mdbook::errors::Error> {
) -> Result<RenderContext, mdbook_core::errors::Error> {
let json_ctx = json!({
"version": mdbook::MDBOOK_VERSION,
"version": mdbook_core::MDBOOK_VERSION,
"root": "tests/long_book_example",
"book": {"sections": chapters, "__non_exhaustive": null},
"config": {
Expand Down
6 changes: 3 additions & 3 deletions src/validation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::errors::Error;
use crate::Config;
use crate::errors::Error;
use epub_builder::EpubVersion;
use mdbook::Config as MdConfig;
use mdbook_core::config::Config as MdConfig;
use std::path::Path;

pub(crate) fn validate_config_epub_version(
Expand All @@ -14,7 +14,7 @@ pub(crate) fn validate_config_epub_version(
return Err(Error::EpubDocCreate(format!(
"Unsupported epub version specified in book.toml: {}",
v
)))
)));
}
None => None,
};
Expand Down
Loading