diff --git a/Cargo.lock b/Cargo.lock index b7555940..31657a6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1302,6 +1302,8 @@ dependencies = [ "log", "pulldown-cmark 0.10.3", "regex", + "serde", + "serde_json", "tempfile", "toml", ] diff --git a/Cargo.toml b/Cargo.toml index a8c4331c..3428025c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,8 @@ log = "0.4.27" mdbook-core = { path = "crates/mdbook-core" } pulldown-cmark = { version = "0.10.3", default-features = false, features = ["html"] } # Do not update, part of the public api. regex = "1.11.1" +serde = { version = "1.0.219", features = ["derive"] } +serde_json = "1.0.140" tempfile = "3.20.0" toml = "0.5.11" # Do not update, see https://github.com/rust-lang/mdBook/issues/2037 @@ -61,8 +63,8 @@ memchr = "2.5.0" opener = "0.8.1" pulldown-cmark.workspace = true regex.workspace = true -serde = { version = "1.0.163", features = ["derive"] } -serde_json = "1.0.96" +serde.workspace = true +serde_json.workspace = true sha2 = "0.10.8" shlex = "1.3.0" tempfile.workspace = true diff --git a/crates/mdbook-core/Cargo.toml b/crates/mdbook-core/Cargo.toml index a92a899a..80e9fcb0 100644 --- a/crates/mdbook-core/Cargo.toml +++ b/crates/mdbook-core/Cargo.toml @@ -12,6 +12,8 @@ anyhow.workspace = true log.workspace = true pulldown-cmark.workspace = true regex.workspace = true +serde.workspace = true +serde_json.workspace = true toml.workspace = true [dev-dependencies] diff --git a/crates/mdbook-core/src/config.rs b/crates/mdbook-core/src/config.rs index 4f91ceae..9ab564c2 100644 --- a/crates/mdbook-core/src/config.rs +++ b/crates/mdbook-core/src/config.rs @@ -12,7 +12,7 @@ //! # use anyhow::Result; //! use std::path::PathBuf; //! use std::str::FromStr; -//! use mdbook::Config; +//! use mdbook_core::config::Config; //! use toml::Value; //! //! # fn run() -> Result<()> { @@ -47,11 +47,10 @@ //! # run().unwrap() //! ``` -use crate::utils::{self, toml_ext::TomlExt}; +use crate::utils::log_backtrace; +use crate::utils::toml_ext::TomlExt; use anyhow::{Context, Error, Result, bail}; use log::{debug, trace, warn}; -use mdbook_core::utils::log_backtrace; -use mdbook_core::utils::toml_ext::TomlExt; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use std::collections::HashMap; use std::env; @@ -814,7 +813,7 @@ impl<'de, T> Updateable<'de> for T where T: Serialize + Deserialize<'de> {} #[cfg(test)] mod tests { use super::*; - use mdbook_core::utils::fs::get_404_output_file; + use crate::utils::fs::get_404_output_file; use serde_json::json; const COMPLEX_CONFIG: &str = r#" diff --git a/crates/mdbook-core/src/lib.rs b/crates/mdbook-core/src/lib.rs index 347d6668..36878aaf 100644 --- a/crates/mdbook-core/src/lib.rs +++ b/crates/mdbook-core/src/lib.rs @@ -6,8 +6,10 @@ /// compatibility checks. pub const MDBOOK_VERSION: &str = env!("CARGO_PKG_VERSION"); +pub mod config; +pub mod utils; + /// The error types used in mdbook. pub mod errors { pub use anyhow::{Error, Result}; } -pub mod utils; diff --git a/src/book/book.rs b/src/book/book.rs index 4e902664..1242c625 100644 --- a/src/book/book.rs +++ b/src/book/book.rs @@ -5,9 +5,9 @@ use std::io::{Read, Write}; use std::path::{Path, PathBuf}; use super::summary::{Link, SectionNumber, Summary, SummaryItem, parse_summary}; -use crate::config::BuildConfig; use anyhow::{Context, Result}; use log::debug; +use mdbook_core::config::BuildConfig; use mdbook_core::utils::bracket_escape; use serde::{Deserialize, Serialize}; diff --git a/src/book/init.rs b/src/book/init.rs index 07e8a43b..13e0d687 100644 --- a/src/book/init.rs +++ b/src/book/init.rs @@ -3,10 +3,10 @@ use std::io::Write; use std::path::PathBuf; use super::MDBook; -use crate::config::Config; use crate::theme; use anyhow::{Context, Result}; use log::{debug, error, info, trace}; +use mdbook_core::config::Config; use mdbook_core::utils::fs::write_file; /// A helper for setting up a new book and its directory structure. diff --git a/src/book/mod.rs b/src/book/mod.rs index 6d9cc670..d3433b4e 100644 --- a/src/book/mod.rs +++ b/src/book/mod.rs @@ -15,6 +15,8 @@ pub use self::summary::{Link, SectionNumber, Summary, SummaryItem, parse_summary use anyhow::{Context, Error, Result, bail}; use log::{debug, error, info, log_enabled, trace, warn}; +use mdbook_core::config::{Config, RustEdition}; +use mdbook_core::utils; use std::ffi::OsString; use std::io::{IsTerminal, Write}; use std::path::{Path, PathBuf}; @@ -27,9 +29,6 @@ use crate::preprocess::{ CmdPreprocessor, IndexPreprocessor, LinkPreprocessor, Preprocessor, PreprocessorContext, }; use crate::renderer::{CmdRenderer, HtmlHandlebars, MarkdownRenderer, RenderContext, Renderer}; -use mdbook_core::utils; - -use crate::config::{Config, RustEdition}; /// The object used to manage and build a book. pub struct MDBook { diff --git a/src/cmd/init.rs b/src/cmd/init.rs index ddfeaad4..386ea4aa 100644 --- a/src/cmd/init.rs +++ b/src/cmd/init.rs @@ -2,7 +2,7 @@ use crate::get_book_dir; use anyhow::Result; use clap::{ArgMatches, Command as ClapCommand, arg}; use mdbook::MDBook; -use mdbook::config; +use mdbook_core::config; use std::io; use std::io::Write; use std::process::Command; diff --git a/src/lib.rs b/src/lib.rs index d0b1af8b..76c744f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,7 +29,7 @@ //! //! ```rust,no_run //! use mdbook::MDBook; -//! use mdbook::config::Config; +//! use mdbook_core::config::Config; //! //! let root_dir = "/path/to/book/root"; //! @@ -78,10 +78,9 @@ //! [user guide]: https://rust-lang.github.io/mdBook/ //! [`RenderContext`]: renderer::RenderContext //! [relevant chapter]: https://rust-lang.github.io/mdBook/for_developers/backends.html -//! [`Config`]: config::Config +//! [`Config`]: mdbook_core::config::Config pub mod book; -pub mod config; pub mod preprocess; pub mod renderer; #[path = "front-end/mod.rs"] @@ -89,6 +88,6 @@ pub mod theme; pub use crate::book::BookItem; pub use crate::book::MDBook; -pub use crate::config::Config; pub use crate::renderer::Renderer; pub use mdbook_core::MDBOOK_VERSION; +pub use mdbook_core::config::Config; diff --git a/src/preprocess/mod.rs b/src/preprocess/mod.rs index 98daf94e..1134ad4d 100644 --- a/src/preprocess/mod.rs +++ b/src/preprocess/mod.rs @@ -1,5 +1,13 @@ //! Book preprocessing. +use crate::book::Book; +use anyhow::Result; +use mdbook_core::config::Config; +use serde::{Deserialize, Serialize}; +use std::cell::RefCell; +use std::collections::HashMap; +use std::path::PathBuf; + pub use self::cmd::CmdPreprocessor; pub use self::index::IndexPreprocessor; pub use self::links::LinkPreprocessor; @@ -8,15 +16,6 @@ mod cmd; mod index; mod links; -use crate::book::Book; -use crate::config::Config; -use anyhow::Result; - -use serde::{Deserialize, Serialize}; -use std::cell::RefCell; -use std::collections::HashMap; -use std::path::PathBuf; - /// Extra information for a `Preprocessor` to give them more context when /// processing a book. #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] diff --git a/src/renderer/html_handlebars/hbs_renderer.rs b/src/renderer/html_handlebars/hbs_renderer.rs index dd90de55..e601c82b 100644 --- a/src/renderer/html_handlebars/hbs_renderer.rs +++ b/src/renderer/html_handlebars/hbs_renderer.rs @@ -1,11 +1,8 @@ use crate::book::{Book, BookItem}; -use crate::config::{BookConfig, Code, Config, HtmlConfig, Playground, RustEdition}; use crate::renderer::html_handlebars::StaticFiles; use crate::renderer::html_handlebars::helpers; use crate::renderer::{RenderContext, Renderer}; use crate::theme::{self, Theme}; -use mdbook_core::utils; -use mdbook_core::utils::fs::get_404_output_file; use std::borrow::Cow; use std::collections::BTreeMap; @@ -17,6 +14,9 @@ use std::sync::LazyLock; use anyhow::{Context, Result, bail}; use handlebars::Handlebars; use log::{debug, info, trace, warn}; +use mdbook_core::config::{BookConfig, Code, Config, HtmlConfig, Playground, RustEdition}; +use mdbook_core::utils; +use mdbook_core::utils::fs::get_404_output_file; use regex::{Captures, Regex}; use serde_json::json; @@ -400,7 +400,7 @@ impl Renderer for HtmlHandlebars { // Render search index #[cfg(feature = "search")] { - let default = crate::config::Search::default(); + let default = mdbook_core::config::Search::default(); let search = html_config.search.as_ref().unwrap_or(&default); if search.enable { super::search::create_files(&search, &mut static_files, &book)?; @@ -1008,9 +1008,8 @@ fn collect_redirects_for_path( #[cfg(test)] mod tests { - use crate::config::TextDirection; - use super::*; + use mdbook_core::config::TextDirection; use pretty_assertions::assert_eq; #[test] diff --git a/src/renderer/html_handlebars/search.rs b/src/renderer/html_handlebars/search.rs index ba9cd274..054e16d9 100644 --- a/src/renderer/html_handlebars/search.rs +++ b/src/renderer/html_handlebars/search.rs @@ -6,12 +6,12 @@ use std::sync::LazyLock; use anyhow::{Context, Result, bail}; use elasticlunr::{Index, IndexBuilder}; use log::{debug, warn}; +use mdbook_core::config::{Search, SearchChapterSettings}; use mdbook_core::utils; use pulldown_cmark::*; use serde::Serialize; use crate::book::{Book, BookItem, Chapter}; -use crate::config::{Search, SearchChapterSettings}; use crate::renderer::html_handlebars::StaticFiles; use crate::theme::searcher; diff --git a/src/renderer/html_handlebars/static_files.rs b/src/renderer/html_handlebars/static_files.rs index ffd07687..de03585e 100644 --- a/src/renderer/html_handlebars/static_files.rs +++ b/src/renderer/html_handlebars/static_files.rs @@ -2,9 +2,9 @@ use anyhow::{Context, Result}; use log::{debug, warn}; +use mdbook_core::config::HtmlConfig; use mdbook_core::utils; -use crate::config::HtmlConfig; use crate::renderer::html_handlebars::helpers::resources::ResourceHelper; use crate::theme::{self, Theme, playground_editor}; @@ -300,8 +300,8 @@ impl StaticFiles { #[cfg(test)] mod tests { use super::*; - use crate::config::HtmlConfig; use crate::theme::Theme; + use mdbook_core::config::HtmlConfig; use mdbook_core::utils::fs::write_file; use tempfile::TempDir; diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index b06983d2..ce4bc025 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -12,9 +12,9 @@ //! [RenderContext]: struct.RenderContext.html use crate::book::Book; -use crate::config::Config; use anyhow::{Context, Result, bail}; use log::{error, info, trace, warn}; +use mdbook_core::config::Config; use serde::{Deserialize, Serialize}; use shlex::Shlex; use std::collections::HashMap;