Skip to content

Commit

Permalink
Fix bookrunner
Browse files Browse the repository at this point in the history
  • Loading branch information
tautschnig committed Feb 7, 2024
1 parent c241e62 commit 3649d21
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ version = "0.1.0"
dependencies = [
"Inflector",
"pulldown-cmark",
"pulldown-cmark-escape",
"rustdoc",
"serde",
"serde_json",
Expand Down Expand Up @@ -774,6 +775,12 @@ dependencies = [
"unicase",
]

[[package]]
name = "pulldown-cmark-escape"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5d8f9aa0e3cbcfaf8bf00300004ee3b72f74770f9cbac93f6928771f613276b"

[[package]]
name = "quote"
version = "1.0.35"
Expand Down
1 change: 1 addition & 0 deletions tools/bookrunner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ publish = false
[dependencies]
Inflector = "0.11.4"
pulldown-cmark = { version = "0.10", default-features = false }
pulldown-cmark-escape = { version = "0.10", default-features = false }
rustdoc = { path = "librustdoc" }
walkdir = "2.3.2"
serde = { version = "1.0", features = ["derive"] }
Expand Down
2 changes: 1 addition & 1 deletion tools/bookrunner/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn find_testable_code<T: doctest::Tester>(
tests.add_test(text, block_info, line);
prev_offset = offset.start;
}
Event::Start(Tag::Heading(level, _, _)) => {
Event::Start(Tag::Heading { level, .. }) => {
register_header = Some(level as u32);
}
Event::Text(ref s) if register_header.is_some() => {
Expand Down
12 changes: 8 additions & 4 deletions tools/bookrunner/src/books.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
util::{self, FailStep, TestProps},
};
use inflector::cases::{snakecase::to_snake_case, titlecase::to_title_case};
use pulldown_cmark::{Event, Parser, Tag};
use pulldown_cmark::{Event, Parser, Tag, TagEnd};
use rustc_span::edition::Edition;
use rustdoc::{
doctest::{make_test, Tester},
Expand Down Expand Up @@ -99,21 +99,25 @@ impl Book {
let mut hierarchy_path: PathBuf =
["tests", "bookrunner", "books", self.name.as_str()].iter().collect();
let mut prev_event_is_text_or_code = false;
let mut current_link_url = String::from("");
for event in parser {
match event {
Event::End(Tag::Item) => {
Event::End(TagEnd::Item) => {
// Pop the current chapter/section from the hierarchy once
// we are done processing it and its subsections.
hierarchy_path.pop();
prev_event_is_text_or_code = false;
}
Event::End(Tag::Link(_, path, _)) => {
Event::Start(Tag::Link { dest_url, .. }) => {
current_link_url = dest_url.into_string();
}
Event::End(TagEnd::Link) => {
// At the start of the link tag, the hierarchy does not yet
// contain the title of the current chapter/section. So, we wait
// for the end of the link tag before adding the path and
// hierarchy of the current chapter/section to the map.
let mut full_path = summary_dir.clone();
full_path.extend(path.split('/'));
full_path.extend(current_link_url.split('/'));
self.hierarchy.insert(full_path, hierarchy_path.clone());
prev_event_is_text_or_code = false;
}
Expand Down
2 changes: 1 addition & 1 deletion tools/bookrunner/src/litani.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT
//! Utilities to interact with the `Litani` build accumulator.
use pulldown_cmark::escape::StrWrite;
use pulldown_cmark_escape::StrWrite;
use serde::Deserialize;
use std::collections::HashMap;
use std::path::Path;
Expand Down

0 comments on commit 3649d21

Please sign in to comment.