diff --git a/src/renderer/html_handlebars/search.rs b/src/renderer/html_handlebars/search.rs
index a9e2f5ca..24d62fda 100644
--- a/src/renderer/html_handlebars/search.rs
+++ b/src/renderer/html_handlebars/search.rs
@@ -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)) => {
diff --git a/tests/rendered_output.rs b/tests/rendered_output.rs
index 7bc5e7ae..7626b9e8 100644
--- a/tests/rendered_output.rs
+++ b/tests/rendered_output.rs
@@ -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`,
diff --git a/tests/searchindex_fixture.json b/tests/searchindex_fixture.json
index 1fcfcdab..85463028 100644
--- a/tests/searchindex_fixture.json
+++ b/tests/searchindex_fixture.json
@@ -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",