Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several fixes for the mdbook-spec preprocessor. #61

Merged
merged 7 commits into from
Jun 27, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix chapter iteration to include nested chapters.
  • Loading branch information
ehuss committed Jun 27, 2024
commit 59586c032a5722f4803d65f41ea33a5ada96f58b
23 changes: 12 additions & 11 deletions mdbook-spec/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,27 +168,28 @@ impl Preprocessor for Spec {

fn run(&self, _ctx: &PreprocessorContext, mut book: Book) -> Result<Book, Error> {
let mut found_rules = BTreeMap::new();
for section in &mut book.sections {
let BookItem::Chapter(ch) = section else {
continue;
book.for_each_mut(|item| {
let BookItem::Chapter(ch) = item else {
return;
};
if ch.is_draft_chapter() {
continue;
return;
}
ch.content = self.rule_definitions(&ch, &mut found_rules);
ch.content = self.admonitions(&ch);
ch.content = std_links::std_links(&ch);
}
for section in &mut book.sections {
let BookItem::Chapter(ch) = section else {
continue;
});
// This is a separate pass because it relies on the modifications of
// the previous passes.
book.for_each_mut(|item| {
let BookItem::Chapter(ch) = item else {
return;
};
if ch.is_draft_chapter() {
continue;
return;
}
ch.content = self.auto_link_references(&ch, &found_rules);
}

});
Ok(book)
}
}