@@ -10,6 +10,24 @@ mod argument_visitor;
10
10
mod markdown;
11
11
mod sections;
12
12
13
+ #[ derive( Debug ) ]
14
+ struct Options {
15
+ pub root : String ,
16
+ }
17
+
18
+ impl From < & PreprocessorContext > for Options {
19
+ fn from ( context : & PreprocessorContext ) -> Self {
20
+ let root = context
21
+ . config
22
+ . get_preprocessor ( "lad-preprocessor" )
23
+ . and_then ( |t| t. get ( "root" ) )
24
+ . and_then ( |v| v. as_str ( ) )
25
+ . map ( |s| s. to_owned ( ) )
26
+ . unwrap_or_default ( ) ;
27
+ Options { root }
28
+ }
29
+ }
30
+
13
31
const LAD_EXTENSION : & str = "lad.json" ;
14
32
15
33
pub struct LADPreprocessor ;
@@ -31,6 +49,7 @@ impl LADPreprocessor {
31
49
/// and `chapter_index` is the index of the chapter among its siblings.
32
50
fn process_lad_chapter (
33
51
_context : & PreprocessorContext ,
52
+ options : & Options ,
34
53
chapter : & mdbook:: book:: Chapter ,
35
54
parent : Option < & mdbook:: book:: Chapter > ,
36
55
chapter_index : usize ,
@@ -45,9 +64,11 @@ impl LADPreprocessor {
45
64
46
65
let parent_path = parent
47
66
. and_then ( |p| p. path . clone ( ) )
48
- . unwrap_or_default ( )
67
+ . unwrap_or_else ( || options . root . clone ( ) . into ( ) )
49
68
. with_extension ( "" ) ;
50
69
70
+ log:: debug!( "Parent path: {:?}" , parent_path) ;
71
+
51
72
let new_chapter = Section :: new (
52
73
parent_path,
53
74
& ladfile,
@@ -75,6 +96,9 @@ impl Preprocessor for LADPreprocessor {
75
96
mut book : mdbook:: book:: Book ,
76
97
) -> mdbook:: errors:: Result < mdbook:: book:: Book > {
77
98
let mut errors = Vec :: new ( ) ;
99
+ let options = Options :: from ( context) ;
100
+
101
+ log:: debug!( "Options: {:?}" , options) ;
78
102
79
103
// first replace children in parents
80
104
book. for_each_mut ( |item| {
@@ -89,6 +113,7 @@ impl Preprocessor for LADPreprocessor {
89
113
if LADPreprocessor :: is_lad_file ( chapter) {
90
114
match LADPreprocessor :: process_lad_chapter (
91
115
context,
116
+ & options,
92
117
chapter,
93
118
Some ( parent) ,
94
119
idx,
@@ -122,6 +147,7 @@ impl Preprocessor for LADPreprocessor {
122
147
}
123
148
let new_chapter = match LADPreprocessor :: process_lad_chapter (
124
149
context,
150
+ & options,
125
151
chapter,
126
152
None ,
127
153
chapter
0 commit comments