Skip to content

Commit 1f865ee

Browse files
committed
Fix chapter iteration to include nested chapters.
1 parent e25adf6 commit 1f865ee

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

mdbook-spec/src/main.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,27 +168,28 @@ impl Preprocessor for Spec {
168168

169169
fn run(&self, _ctx: &PreprocessorContext, mut book: Book) -> Result<Book, Error> {
170170
let mut found_rules = BTreeMap::new();
171-
for section in &mut book.sections {
172-
let BookItem::Chapter(ch) = section else {
173-
continue;
171+
book.for_each_mut(|item| {
172+
let BookItem::Chapter(ch) = item else {
173+
return;
174174
};
175175
if ch.is_draft_chapter() {
176-
continue;
176+
return;
177177
}
178178
ch.content = self.rule_definitions(&ch, &mut found_rules);
179179
ch.content = self.admonitions(&ch);
180180
ch.content = std_links::std_links(&ch);
181-
}
182-
for section in &mut book.sections {
183-
let BookItem::Chapter(ch) = section else {
184-
continue;
181+
});
182+
// This is a separate pass because it relies on the modifications of
183+
// the previous passes.
184+
book.for_each_mut(|item| {
185+
let BookItem::Chapter(ch) = item else {
186+
return;
185187
};
186188
if ch.is_draft_chapter() {
187-
continue;
189+
return;
188190
}
189191
ch.content = self.auto_link_references(&ch, &found_rules);
190-
}
191-
192+
});
192193
Ok(book)
193194
}
194195
}

0 commit comments

Comments
 (0)