From 208f4bcb66474d5b54f02bea665cb568795f9bcc Mon Sep 17 00:00:00 2001 From: Will Lachance Date: Wed, 24 Apr 2024 14:09:14 -0400 Subject: [PATCH] HTML Search: Fix removal of unwanted anchor content from search results (#12321) --- CHANGES.rst | 2 ++ sphinx/themes/basic/static/searchtools.js | 2 +- tests/js/searchtools.js | 6 +++--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index ea855c69f..02cc27ef0 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 ------- diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js index 92da3f8b2..eaed90953 100644 --- a/sphinx/themes/basic/static/searchtools.js +++ b/sphinx/themes/basic/static/searchtools.js @@ -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) { diff --git a/tests/js/searchtools.js b/tests/js/searchtools.js index 4f9984dd4..99ebdafb1 100644 --- a/tests/js/searchtools.js +++ b/tests/js/searchtools.js @@ -100,15 +100,15 @@ describe("htmlToText", function() {
-

Getting Started

+

Getting Started

Some text

-

Other Section

+

Other Section

Other text

-

Yet Another Section

+

Yet Another Section

More text