Fix search for custom heading attributes

This commit is contained in:
Eric Huss 2023-05-28 11:55:56 -07:00
parent e3be293420
commit 1db52ff531
3 changed files with 11 additions and 4 deletions

View File

@ -138,9 +138,11 @@ fn render_item(
in_heading = true;
}
Event::End(Tag::Heading(i, ..)) if i as u32 <= max_section_depth => {
Event::End(Tag::Heading(i, id, _classes)) if i as u32 <= max_section_depth => {
in_heading = false;
section_id = Some(utils::unique_id_from_content(&heading, &mut id_counter));
section_id = id
.map(|id| id.to_string())
.or_else(|| Some(utils::unique_id_from_content(&heading, &mut id_counter)));
breadcrumbs.push(heading.clone());
}
Event::Start(Tag::FootnoteDefinition(name)) => {

View File

@ -755,6 +755,7 @@ mod search {
let no_headers = get_doc_ref("first/no-headers.html");
let duplicate_headers_1 = get_doc_ref("first/duplicate-headers.html#header-text-1");
let conclusion = get_doc_ref("conclusion.html#conclusion");
let heading_attrs = get_doc_ref("first/heading-attributes.html#both");
let bodyidx = &index["index"]["index"]["body"]["root"];
let textidx = &bodyidx["t"]["e"]["x"]["t"];
@ -786,6 +787,10 @@ mod search {
docs[&no_headers]["body"],
"Capybara capybara capybara. Capybara capybara capybara. ThisLongWordIsIncludedSoWeCanCheckThatSufficientlyLongWordsAreOmittedFromTheSearchIndex."
);
assert_eq!(
docs[&heading_attrs]["breadcrumbs"],
"First Chapter » Heading Attributes » Heading with id and classes"
);
}
// Setting this to `true` may cause issues with `cargo watch`,

View File

@ -23,9 +23,9 @@
"first/duplicate-headers.html#header-text",
"first/duplicate-headers.html#header-text-1",
"first/duplicate-headers.html#header-text-2",
"first/heading-attributes.html#heading-attributes",
"first/heading-attributes.html#attrs",
"first/heading-attributes.html#heading-with-classes",
"first/heading-attributes.html#heading-with-id-and-classes",
"first/heading-attributes.html#both",
"second.html#second-chapter",
"second/nested.html#testing-relative-links-for-the-print-page",
"second/nested.html#some-section",