Skip to content

Commit

Permalink
HTML Search: Fix removal of unwanted anchor content from search resul…
Browse files Browse the repository at this point in the history
…ts (#12321)
  • Loading branch information
wlach committed Apr 24, 2024
1 parent 2008aa8 commit 208f4bc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Bugs fixed
* #12162: Fix a performance regression in the C domain that has
been present since version 3.0.0.
Patch by Donald Hunter.
* #12320: Fix removal of anchors from search summaries (regression in 7.3.0).
Patch by Will Lachance.

Testing
-------
Expand Down
2 changes: 1 addition & 1 deletion sphinx/themes/basic/static/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const Search = {

htmlToText: (htmlString, anchor) => {
const htmlElement = new DOMParser().parseFromString(htmlString, 'text/html');
for (const removalQuery of [".headerlinks", "script", "style"]) {
for (const removalQuery of [".headerlink", "script", "style"]) {
htmlElement.querySelectorAll(removalQuery).forEach((el) => { el.remove() });
}
if (anchor) {
Expand Down
6 changes: 3 additions & 3 deletions tests/js/searchtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ describe("htmlToText", function() {
</style>
<!-- main content -->
<section id="getting-started">
<h1>Getting Started</h1>
<h1>Getting Started <a class="headerlink" href="#getting-started" title="Link to this heading">¶</a></h1>
<p>Some text</p>
</section>
<section id="other-section">
<h1>Other Section</h1>
<h1>Other Section <a class="headerlink" href="#other-section" title="Link to this heading">¶</a></h1>
<p>Other text</p>
</section>
<section id="yet-another-section">
<h1>Yet Another Section</h1>
<h1>Yet Another Section <a class="headerlink" href="#yet-another-section" title="Link to this heading">¶</a></h1>
<p>More text</p>
</section>
</div>
Expand Down

0 comments on commit 208f4bc

Please sign in to comment.