Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade mdbook to 0.4.40, align local dependencies with mdbook versio… #114

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
91 changes: 9 additions & 82 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
authors = ["Michael Bryan <michaelfbryan@gmail.com>"]
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"
Expand All @@ -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"
Expand All @@ -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
Expand Down
29 changes: 17 additions & 12 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -193,13 +193,18 @@ impl<'a> Generator<'a> {
fn render_chapter(&self, ch: &Chapter) -> Result<String, RenderError> {
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);
Expand Down Expand Up @@ -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 `<hash>.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
}
Expand Down Expand Up @@ -528,7 +533,7 @@ impl EventQuoteConverter {
self.convert_text = false;
event
}
Event::End(Tag::CodeBlock(_)) => {
Event::End(TagEnd::CodeBlock) => {
self.convert_text = true;
event
}
Expand Down
6 changes: 3 additions & 3 deletions src/resources/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ fn find_assets_in_markdown(chapter_src_content: &str) -> Result<Vec<String>, 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) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down