diff --git a/Cargo.lock b/Cargo.lock index 852cadac8..5f64a17d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -111,7 +111,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi 0.1.19", + "hermit-abi", "libc", "winapi", ] @@ -415,19 +415,6 @@ dependencies = [ "regex", ] -[[package]] -name = "env_logger" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd405aab171cb85d6735e5c8d9db038c17d3ca007a4d2c25f337935c3d90580" -dependencies = [ - "humantime", - "is-terminal", - "log", - "regex", - "termcolor", -] - [[package]] name = "env_logger" version = "0.11.3" @@ -644,20 +631,6 @@ dependencies = [ "wasi", ] -[[package]] -name = "handlebars" -version = "4.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faa67bab9ff362228eb3d00bd024a4965d8231bbb7921167f0cfa66c6626b225" -dependencies = [ - "log", - "pest", - "pest_derive", - "serde", - "serde_json", - "thiserror", -] - [[package]] name = "handlebars" version = "5.1.2" @@ -696,12 +669,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - [[package]] name = "html-escape" version = "0.2.13" @@ -781,17 +748,6 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "is-terminal" -version = "0.4.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" -dependencies = [ - "hermit-abi 0.3.9", - "libc", - "windows-sys 0.52.0", -] - [[package]] name = "is_terminal_polyfill" version = "1.70.0" @@ -876,13 +832,13 @@ dependencies = [ "chrono", "clap 4.5.4", "clap_complete", - "env_logger 0.11.3", - "handlebars 5.1.2", + "env_logger", + "handlebars", "log", "memchr", "once_cell", "opener", - "pulldown-cmark 0.10.3", + "pulldown-cmark", "regex", "serde", "serde_json", @@ -894,20 +850,20 @@ dependencies = [ [[package]] name = "mdbook-epub" -version = "0.4.37" +version = "0.4.40" dependencies = [ "const_format", - "env_logger 0.10.2", + "env_logger", "epub", "epub-builder", "eyre", - "handlebars 4.5.0", + "handlebars", "html_parser", "log", "mdbook", "mime_guess", "mockall", - "pulldown-cmark 0.9.6", + "pulldown-cmark", "semver", "serde", "serde_derive", @@ -1190,18 +1146,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "pulldown-cmark" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b" -dependencies = [ - "bitflags 2.5.0", - "getopts", - "memchr", - "unicase", -] - [[package]] name = "pulldown-cmark" version = "0.10.3" @@ -1209,6 +1153,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76979bea66e7875e7509c4ec5300112b316af87fa7a252ca91c448b32dfe3993" dependencies = [ "bitflags 2.5.0", + "getopts", "memchr", "pulldown-cmark-escape", "unicase", @@ -1514,15 +1459,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "termcolor" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" -dependencies = [ - "winapi-util", -] - [[package]] name = "terminal_size" version = "0.3.0" @@ -1846,15 +1782,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[[package]] -name = "winapi-util" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" -dependencies = [ - "windows-sys 0.52.0", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" diff --git a/Cargo.toml b/Cargo.toml index de3efd0ab..0a1bf34db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ authors = ["Michael Bryan "] description = "An EPUB renderer for mdbook." name = "mdbook-epub" -version = "0.4.37" +version = "0.4.40" readme = "README.md" license = "MIT" repository = "https://github.com/Michael-F-Bryan/mdbook-epub" @@ -25,17 +25,17 @@ doc = false eyre = "0.6" epub-builder = "0.7" thiserror = "1.0.49" -pulldown-cmark = "0.9.3" +pulldown-cmark = "0.10.0" semver = "1.0.17" serde = { version = "1.0.163", features = ["derive"] } serde_derive = "1.0" serde_json = "1.0.96" structopt = "0.3.26" mime_guess = "2.0" -env_logger = "0.10.0" +env_logger = "0.11.1" log = "0.4.17" -mdbook = { version = "0.4.37", default-features = false } -handlebars = "4.3.7" +mdbook = { version = "0.4.40", default-features = false } +handlebars = "5.0" toml = "0.5.11" # downgraded due to parent 'mdbook' dependency and error there html_parser = "0.7.0" url = "2.3" @@ -45,11 +45,11 @@ const_format = "0.2.31" uuid = "1.8" [dev-dependencies] -tempfile = "3" +tempfile = "3.4" epub = "2.1.1" serial_test = "2.0.0" mockall = "0.11" -env_logger = "0.10.0" +env_logger = "0.11.1" [profile.release] lto = true diff --git a/src/generator.rs b/src/generator.rs index 1512924e6..4c681e149 100644 --- a/src/generator.rs +++ b/src/generator.rs @@ -9,11 +9,11 @@ use std::{ }; use epub_builder::{EpubBuilder, EpubContent, ZipLibrary}; -use handlebars::{Handlebars, RenderError}; +use handlebars::{Handlebars, RenderError, RenderErrorReason}; use html_parser::{Dom, Node}; use mdbook::book::{BookItem, Chapter}; use mdbook::renderer::RenderContext; -use pulldown_cmark::{CowStr, Event, html, Tag}; +use pulldown_cmark::{CowStr, Event, html, Tag, TagEnd}; use url::Url; use urlencoding::encode; @@ -193,13 +193,18 @@ impl<'a> Generator<'a> { fn render_chapter(&self, ch: &Chapter) -> Result { let chapter_dir = if let Some(chapter_file_path) = &ch.path { chapter_file_path.parent().ok_or_else(|| { - RenderError::new(format!("No CSS found by a path = {:?}", ch.path)) + RenderError::from( + RenderErrorReason::Other(format!("No CSS found by a path = {:?}", ch.path)) + ) })? } else { - return Err(RenderError::new(format!( - "Draft chapter: '{}' could not be rendered.", - ch.name - ))); + return Err( + RenderError::from( + RenderErrorReason::Other(format!( + "Draft chapter: '{}' could not be rendered.", + ch.name + ))) + ); }; let mut body = String::new(); let parser = utils::create_new_pull_down_parser(&ch.content); @@ -418,12 +423,12 @@ impl<'a> AssetLinkFilter<'a> { fn apply(&self, event: Event<'a>) -> Event<'a> { trace!("AssetLinkFilter: Processing Event = {:?}", &event); match event { - Event::Start(Tag::Image(ty, ref url, ref title)) => { - if let Some(asset) = self.assets.get(&url.to_string()) { + Event::Start(Tag::Image{link_type, ref dest_url, ref title, ref id}) => { + if let Some(asset) = self.assets.get(&dest_url.to_string()) { // PREPARE info for replacing original REMOTE link by `.ext` value inside chapter content - debug!("Found URL '{}' by Event", &url); + debug!("Found URL '{}' by Event", &dest_url); let new = self.path_prefix(asset.filename.as_path()); - Event::Start(Tag::Image(ty, CowStr::from(new), title.to_owned())) + Event::Start(Tag::Image{link_type, dest_url: CowStr::from(new), title: title.to_owned(), id: id.to_owned()}) } else { event } @@ -528,7 +533,7 @@ impl EventQuoteConverter { self.convert_text = false; event } - Event::End(Tag::CodeBlock(_)) => { + Event::End(TagEnd::CodeBlock) => { self.convert_text = true; event } diff --git a/src/resources/resource.rs b/src/resources/resource.rs index a86b48fc1..9735fcaaf 100644 --- a/src/resources/resource.rs +++ b/src/resources/resource.rs @@ -137,10 +137,10 @@ fn find_assets_in_markdown(chapter_src_content: &str) -> Result, Err // that will process chapter content and find assets for event in pull_down_parser { match event { - Event::Start(Tag::Image(_, dest, _)) => { - found_asset.push(dest.to_string()); + Event::Start(Tag::Image{link_type: _, dest_url, title: _, id: _}) => { + found_asset.push(dest_url.to_string()); } - Event::Html(html) => { + Event::Html(html) | Event::InlineHtml(html) => { let content = html.into_string(); if let Ok(dom) = Dom::parse(&content) { diff --git a/src/utils.rs b/src/utils.rs index 55b062866..936e83dd1 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -4,7 +4,7 @@ use std::path::{Component, Path, PathBuf}; use url::Url; use uuid::Uuid; -pub(crate) fn create_new_pull_down_parser(text: &str) -> Parser<'_, '_> { +pub(crate) fn create_new_pull_down_parser(text: &str) -> Parser<'_> { let mut opts = Options::empty(); opts.insert(Options::ENABLE_TABLES); opts.insert(Options::ENABLE_FOOTNOTES);