diff options
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | Cargo.toml | 3 | ||||
-rw-r--r-- | src/book_config.rs | 18 |
3 files changed, 14 insertions, 8 deletions
@@ -1028,6 +1028,7 @@ dependencies = [ "semver", "serde", "serde_json", + "toml 0.5.11", "toml 0.7.6", "toml_edit", ] @@ -33,6 +33,9 @@ regex = "1.9.3" semver = "1.0.18" serde = { version = "1.0.183", features = ["derive"] } serde_json = "1.0.104" +# The version of toml that mdbook uses internally (and uses in it's public api) +# Only used for compatilibilty with the mdbook public api +toml_mdbook = { package = "toml", version = "0.5.11" } toml = "0.7.6" toml_edit = { version = "0.19.14", optional = true } diff --git a/src/book_config.rs b/src/book_config.rs index 696a684..c6454f1 100644 --- a/src/book_config.rs +++ b/src/book_config.rs @@ -5,15 +5,17 @@ use std::collections::HashMap; use crate::types::AdmonitionDefaults; +/// Loads the plugin configuration from mdbook internals. +/// +/// Roundtrips config to string, to avoid linking the plugin's internal version of toml +/// to the one publically exposed by the mdbook library. pub(crate) fn admonish_config_from_context(ctx: &PreprocessorContext) -> Result<Config> { - let table: toml::Table = ctx - .config - .get_preprocessor("admonish") - .context("No configuration for mdbook-admonish in book.toml")? - .to_owned(); - table - .try_into() - .context("Invalid mdbook-admonish configuration in book.toml") + let table: String = toml_mdbook::to_string( + ctx.config + .get_preprocessor("admonish") + .context("No configuration for mdbook-admonish in book.toml")?, + )?; + toml::from_str(&table).context("Invalid mdbook-admonish configuration in book.toml") } #[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)] |