diff --git a/crates/lad_backends/mdbook_lad_preprocessor/src/lib.rs b/crates/lad_backends/mdbook_lad_preprocessor/src/lib.rs index bacb7a2bdb..81634677ad 100644 --- a/crates/lad_backends/mdbook_lad_preprocessor/src/lib.rs +++ b/crates/lad_backends/mdbook_lad_preprocessor/src/lib.rs @@ -6,6 +6,7 @@ use mdbook::{ preprocess::{Preprocessor, PreprocessorContext}, }; use sections::{Section, SectionData}; +use std::sync::OnceLock; mod argument_visitor; mod markdown; mod sections; @@ -29,6 +30,8 @@ impl From<&PreprocessorContext> for Options { } const LAD_EXTENSION: &str = "lad.json"; +// global for options +static OPTIONS: OnceLock = OnceLock::new(); pub struct LADPreprocessor; @@ -49,7 +52,6 @@ impl LADPreprocessor { /// and `chapter_index` is the index of the chapter among its siblings. fn process_lad_chapter( _context: &PreprocessorContext, - options: &Options, chapter: &mdbook::book::Chapter, parent: Option<&mdbook::book::Chapter>, chapter_index: usize, @@ -64,7 +66,7 @@ impl LADPreprocessor { let parent_path = parent .and_then(|p| p.path.clone()) - .unwrap_or_else(|| options.root.clone().into()) + .unwrap_or_default() .with_extension(""); log::debug!("Parent path: {:?}", parent_path); @@ -99,6 +101,9 @@ impl Preprocessor for LADPreprocessor { let options = Options::from(context); log::debug!("Options: {:?}", options); + OPTIONS + .set(options) + .map_err(|_| mdbook::errors::Error::msg("could not initialize options"))?; // first replace children in parents book.for_each_mut(|item| { @@ -113,7 +118,6 @@ impl Preprocessor for LADPreprocessor { if LADPreprocessor::is_lad_file(chapter) { match LADPreprocessor::process_lad_chapter( context, - &options, chapter, Some(parent), idx, @@ -147,7 +151,6 @@ impl Preprocessor for LADPreprocessor { } let new_chapter = match LADPreprocessor::process_lad_chapter( context, - &options, chapter, None, chapter diff --git a/crates/lad_backends/mdbook_lad_preprocessor/src/sections.rs b/crates/lad_backends/mdbook_lad_preprocessor/src/sections.rs index aefa59e2db..87ac40d1de 100644 --- a/crates/lad_backends/mdbook_lad_preprocessor/src/sections.rs +++ b/crates/lad_backends/mdbook_lad_preprocessor/src/sections.rs @@ -286,7 +286,7 @@ impl<'a> Section<'a> { } SectionData::InstancesSummary => { let instances = self.ladfile.globals.iter().collect::>(); - let types_directory = PathBuf::from("/").join(self.parent_path.join("types")); + let types_directory = PathBuf::from("./types"); vec![SectionItem::InstancesSummary { instances, ladfile: self.ladfile, @@ -355,7 +355,7 @@ impl<'a> Section<'a> { ] } SectionData::FunctionDetail { function } => { - let types_directory = self.parent_path.join("../types"); + let types_directory = PathBuf::from("../types"); vec![SectionItem::FunctionDetails { function, ladfile: self.ladfile, diff --git a/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/expected/parent/lad/functions/hello_world.md b/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/expected/parent/lad/functions/hello_world.md index 47ce0b7268..b0fa92768f 100644 --- a/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/expected/parent/lad/functions/hello_world.md +++ b/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/expected/parent/lad/functions/hello_world.md @@ -6,11 +6,11 @@ | Name | Type | Documentation | | --- | --- | --- | -| **arg1** | [usize](parent/lad/functions/../types/usize.md) | No Documentation 🚧 | +| **arg1** | [usize](../types/usize.md) | No Documentation 🚧 | #### Returns | Name | Type | Documentation | | --- | --- | --- | -| **arg0** | [usize](parent/lad/functions/../types/usize.md) | No Documentation 🚧 | +| **arg0** | [usize](../types/usize.md) | No Documentation 🚧 | diff --git a/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/expected/parent/lad/globals.md b/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/expected/parent/lad/globals.md index 55e506f43d..0fbafcca88 100644 --- a/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/expected/parent/lad/globals.md +++ b/crates/lad_backends/mdbook_lad_preprocessor/tests/books/example_ladfile/expected/parent/lad/globals.md @@ -10,8 +10,8 @@ Instances containing actual accessible values\. | Instance | Type | | --- | --- | -| `my_non_static_instance` | Vec\<[UnitType](/parent/lad/types/unittype.md)\> | -| `map` | HashMap\<[String](/parent/lad/types/string.md), [String](/parent/lad/types/string.md) \| [String](/parent/lad/types/string.md)\> | +| `my_non_static_instance` | Vec\<[UnitType](./types/unittype.md)\> | +| `map` | HashMap\<[String](./types/string.md), [String](./types/string.md) \| [String](./types/string.md)\> | ### Static Instances @@ -19,5 +19,5 @@ Static type references, existing for the purpose of typed static function calls\ | Instance | Type | | --- | --- | -| `my_static_instance` | StructType\<[usize](/parent/lad/types/usize.md)\> | +| `my_static_instance` | StructType\<[usize](./types/usize.md)\> |