Skip to content

Commit

Permalink
Fix search for custom heading attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed May 28, 2023
1 parent e3be293 commit 1db52ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/renderer/html_handlebars/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) => {
Expand Down
5 changes: 5 additions & 0 deletions tests/rendered_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down Expand Up @@ -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`,
Expand Down
4 changes: 2 additions & 2 deletions tests/searchindex_fixture.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1db52ff

Please sign in to comment.