Skip to content
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
963 changes: 208 additions & 755 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ anyhow = "1.0.86"
clap = { version = "4.5.8", features = ["derive"] }
env_logger = "0.11.3"
log = "0.4.22"
mdbook = "0.4.43"
mdbook-core = "0.5.0"
mdbook-driver = "0.5.0"
mdbook-preprocessor = "0.5.0"
mdbook-renderer = "0.5.0"
pulldown-cmark = "0.13.0"
semver = "1.0.23"
serde = { version = "1.0.204", features = ["derive"] }
Expand Down
1 change: 0 additions & 1 deletion book/book.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[book]
authors = ["Daniëlle Huisman"]
language = "en"
multilingual = false
src = "src"
title = "mdBook Plugins"

Expand Down
1 change: 1 addition & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ allow = [
"BSD-2-Clause",
"BSD-3-Clause",
"BSL-1.0",
"CC-BY-4.0",
"CC0-1.0",
"ISC",
"MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/mdbook-tabs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ anyhow.workspace = true
clap.workspace = true
env_logger.workspace = true
log.workspace = true
mdbook.workspace = true
mdbook-driver.workspace = true
mdbook-plugin-utils = { path = "../mdbook-plugin-utils", version = "0.2.1" }
mdbook-preprocessor.workspace = true
pulldown-cmark.workspace = true
semver.workspace = true
serde.workspace = true
Expand Down
15 changes: 7 additions & 8 deletions packages/mdbook-tabs/src/bin/mdbook-tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ use std::{
use anyhow::{Result, anyhow};
use clap::{Args, Parser, Subcommand};
use log::warn;
use mdbook::{
MDBook,
preprocess::{CmdPreprocessor, Preprocessor},
};
use mdbook_driver::MDBook;
use mdbook_preprocessor::Preprocessor;
use mdbook_preprocessor::{MDBOOK_VERSION, parse_input};
use mdbook_tabs::TabsPreprocessor;
use semver::{Version, VersionReq};

Expand Down Expand Up @@ -72,23 +71,23 @@ fn handle_supports(
preprocessor: &dyn Preprocessor,
SupportsArgs { renderer }: &SupportsArgs,
) -> Result<()> {
match preprocessor.supports_renderer(renderer) {
match preprocessor.supports_renderer(renderer)? {
true => Ok(()),
false => Err(anyhow!("Renderer `{renderer}` is not supported.")),
}
}

fn handle_preprocessing<R: Read>(preprocessor: &dyn Preprocessor, reader: R) -> Result<()> {
let (ctx, book) = CmdPreprocessor::parse_input(reader)?;
let (ctx, book) = parse_input(reader)?;

let book_version = Version::parse(&ctx.mdbook_version)?;
let version_req = VersionReq::parse(mdbook::MDBOOK_VERSION)?;
let version_req = VersionReq::parse(MDBOOK_VERSION)?;

if !version_req.matches(&book_version) {
warn!(
"The {} plugin was built against version {} of mdbook, but we're being called from version {}",
preprocessor.name(),
mdbook::MDBOOK_VERSION,
MDBOOK_VERSION,
ctx.mdbook_version
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/mdbook-tabs/src/parser/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::ops::Range;

use anyhow::{Result, bail};
use log::debug;
use mdbook::book::Chapter;
use mdbook_plugin_utils::markdown::parse_blocks;
use mdbook_preprocessor::book::Chapter;
use pulldown_cmark::Event;

use crate::config::{TabConfig, TabsConfig};
Expand Down
13 changes: 6 additions & 7 deletions packages/mdbook-tabs/src/preprocessor.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use std::str;

use anyhow::{Result, bail};
use mdbook::{
BookItem,
book::Book,
preprocess::{Preprocessor, PreprocessorContext},
use mdbook_preprocessor::{
Preprocessor, PreprocessorContext,
book::{Book, BookItem},
};

use crate::{parser::tabs::parse_tabs, tabs::tabs};
Expand All @@ -31,13 +30,13 @@ impl Preprocessor for TabsPreprocessor {
fn run(&self, _ctx: &PreprocessorContext, book: Book) -> Result<Book> {
let mut book = book.clone();

process_items(&mut book.sections)?;
process_items(&mut book.items)?;

Ok(book)
}

fn supports_renderer(&self, _renderer: &str) -> bool {
true
fn supports_renderer(&self, _renderer: &str) -> Result<bool> {
Ok(true)
}
}

Expand Down
5 changes: 4 additions & 1 deletion packages/mdbook-trunk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ fs_extra = "1.3.0"
html_parser = "0.7.0"
htmlentity = "1.3.2"
log.workspace = true
mdbook.workspace = true
mdbook-core.workspace = true
mdbook-driver.workspace = true
mdbook-plugin-utils = { path = "../mdbook-plugin-utils", version = "0.2.1" }
mdbook-preprocessor.workspace = true
mdbook-renderer.workspace = true
peekread = "0.1.1"
pulldown-cmark.workspace = true
semver.workspace = true
Expand Down
21 changes: 10 additions & 11 deletions packages/mdbook-trunk/src/bin/mdbook-trunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use anyhow::{Result, anyhow};
use clap::{Args, Parser, Subcommand};
use fs_extra::dir::{CopyOptions, DirOptions, copy, get_dir_content2};
use log::warn;
use mdbook::{
MDBook, Renderer,
preprocess::{CmdPreprocessor, Preprocessor},
renderer::RenderContext,
};
use mdbook_core::MDBOOK_VERSION;
use mdbook_driver::MDBook;
use mdbook_preprocessor::{Preprocessor, parse_input};
use mdbook_renderer::{RenderContext, Renderer};
use mdbook_trunk::{TrunkPreprocessor, TrunkRenderer};
use peekread::{BufPeekReader, PeekRead};
use semver::{Version, VersionReq};
Expand Down Expand Up @@ -124,23 +123,23 @@ fn handle_supports(
preprocessor: &dyn Preprocessor,
SupportsArgs { renderer }: &SupportsArgs,
) -> Result<()> {
match preprocessor.supports_renderer(renderer) {
match preprocessor.supports_renderer(renderer)? {
true => Ok(()),
false => Err(anyhow!("Renderer `{renderer}` is not supported.")),
}
}

fn handle_preprocessing<R: Read>(preprocessor: &dyn Preprocessor, reader: R) -> Result<()> {
let (ctx, book) = CmdPreprocessor::parse_input(reader)?;
let (ctx, book) = parse_input(reader)?;

let book_version = Version::parse(&ctx.mdbook_version)?;
let version_req = VersionReq::parse(mdbook::MDBOOK_VERSION)?;
let version_req = VersionReq::parse(MDBOOK_VERSION)?;

if !version_req.matches(&book_version) {
warn!(
"The {} plugin was built against version {} of mdbook, but we're being called from version {}",
preprocessor.name(),
mdbook::MDBOOK_VERSION,
MDBOOK_VERSION,
ctx.mdbook_version
);
}
Expand All @@ -155,13 +154,13 @@ fn handle_renderer<R: Read>(renderer: &dyn Renderer, reader: R) -> Result<()> {
let ctx = RenderContext::from_json(reader).unwrap();

let book_version = Version::parse(&ctx.version)?;
let version_req = VersionReq::parse(mdbook::MDBOOK_VERSION)?;
let version_req = VersionReq::parse(MDBOOK_VERSION)?;

if !version_req.matches(&book_version) {
warn!(
"The {} plugin was built against version {} of mdbook, but we're being called from version {}",
renderer.name(),
mdbook::MDBOOK_VERSION,
MDBOOK_VERSION,
ctx.version
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/mdbook-trunk/src/parser/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ops::Range;

use anyhow::Result;
use log::debug;
use mdbook::book::Chapter;
use mdbook_core::book::Chapter;
use mdbook_plugin_utils::markdown::parse_code_blocks;

use crate::config::Config;
Expand Down
2 changes: 1 addition & 1 deletion packages/mdbook-trunk/src/parser/iframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use anyhow::Result;
use html_parser::{Dom, Node};
use htmlentity::entity::{ICodedDataTrait, decode};
use log::debug;
use mdbook::book::Chapter;
use mdbook_core::book::Chapter;
use mdbook_plugin_utils::markdown::parse_blocks;
use pulldown_cmark::{Event, TagEnd};

Expand Down
13 changes: 6 additions & 7 deletions packages/mdbook-trunk/src/preprocessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use std::{env, str};

use anyhow::Result;
use cargo::{GlobalContext, core::Workspace, util::important_paths::find_root_manifest_for_wd};
use mdbook::{
BookItem,
book::Book,
preprocess::{Preprocessor, PreprocessorContext},
use mdbook_preprocessor::{
Preprocessor, PreprocessorContext,
book::{Book, BookItem},
};

use crate::{parser::definition::parse_definitions, trunk::trunk};
Expand Down Expand Up @@ -35,13 +34,13 @@ impl Preprocessor for TrunkPreprocessor {
let gctx = GlobalContext::default()?;
let workspace = Workspace::new(&find_root_manifest_for_wd(&env::current_dir()?)?, &gctx)?;

process_items(&workspace, &mut book.sections)?;
process_items(&workspace, &mut book.items)?;

Ok(book)
}

fn supports_renderer(&self, _renderer: &str) -> bool {
true
fn supports_renderer(&self, _renderer: &str) -> Result<bool> {
Ok(true)
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/mdbook-trunk/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{collections::HashSet, env};

use anyhow::Result;
use cargo::{GlobalContext, core::Workspace, util::important_paths::find_root_manifest_for_wd};
use mdbook::{BookItem, Renderer, renderer::RenderContext};
use mdbook_renderer::{RenderContext, Renderer, book::BookItem};

use crate::{config::BuildConfig, parser::iframe::parse_iframes, trunk::build};

Expand All @@ -29,7 +29,7 @@ impl Renderer for TrunkRenderer {
let gctx = GlobalContext::default()?;
let workspace = Workspace::new(&find_root_manifest_for_wd(&env::current_dir()?)?, &gctx)?;

let builds = process_items(&ctx.book.sections)?;
let builds = process_items(&ctx.book.items)?;

// let mut handles = vec![];
for build_config in builds {
Expand Down
Loading