From 206a00915b350fdb5f0fd9dd6107e743b6338612 Mon Sep 17 00:00:00 2001 From: Michael Bryan Date: Sun, 16 Sep 2018 14:22:50 +0800 Subject: [PATCH 1/2] Export the mdbook version from the crate root --- src/lib.rs | 6 ++++++ src/renderer/mod.rs | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2c91e283af..028a2ba87b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -114,6 +114,12 @@ pub mod renderer; pub mod theme; pub mod utils; +/// The current version of `mdbook`. +/// +/// This is provided as a way for custom preprocessors and renderers to do +/// compatibility checks. +pub const MDBOOK_VERSION: &str = env!("CARGO_PKG_VERSION"); + pub use book::BookItem; pub use book::MDBook; pub use config::Config; diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 906f7e2745..78d208e222 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -26,8 +26,6 @@ use book::Book; use config::Config; use errors::*; -const MDBOOK_VERSION: &str = env!("CARGO_PKG_VERSION"); - /// An arbitrary `mdbook` backend. /// /// Although it's quite possible for you to import `mdbook` as a library and @@ -78,7 +76,7 @@ impl RenderContext { RenderContext { book: book, config: config, - version: MDBOOK_VERSION.to_string(), + version: ::MDBOOK_VERSION.to_string(), root: root.into(), destination: destination.into(), } From 5dce5399289cdaa8d3a95fd00ff79f27968e3dce Mon Sep 17 00:00:00 2001 From: Michael Bryan Date: Sun, 16 Sep 2018 14:27:37 +0800 Subject: [PATCH 2/2] Notify preprocessors of the mdbook version and add __non_exhaustive elements --- src/preprocess/mod.rs | 11 ++++++++++- src/renderer/mod.rs | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/preprocess/mod.rs b/src/preprocess/mod.rs index 5f59c5bf71..87a135db83 100644 --- a/src/preprocess/mod.rs +++ b/src/preprocess/mod.rs @@ -21,12 +21,21 @@ pub struct PreprocessorContext { pub config: Config, /// The `Renderer` this preprocessor is being used with. pub renderer: String, + /// The calling `mdbook` version. + pub mdbook_version: String, + __non_exhaustive: (), } impl PreprocessorContext { /// Create a new `PreprocessorContext`. pub(crate) fn new(root: PathBuf, config: Config, renderer: String) -> Self { - PreprocessorContext { root, config, renderer } + PreprocessorContext { + root, + config, + renderer, + mdbook_version: ::MDBOOK_VERSION.to_string(), + __non_exhaustive: (), + } } } diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 78d208e222..41176ae0dc 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -64,6 +64,7 @@ pub struct RenderContext { /// renderers to cache intermediate results, this directory is not /// guaranteed to be empty or even exist. pub destination: PathBuf, + __non_exhaustive: (), } impl RenderContext { @@ -79,6 +80,7 @@ impl RenderContext { version: ::MDBOOK_VERSION.to_string(), root: root.into(), destination: destination.into(), + __non_exhaustive: (), } }