From f280ebb00004bd39c4fe4a090e4faae008697b7f Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 26 Jun 2022 23:15:56 +0900 Subject: [PATCH 1/4] HTML Search: HTML tags are displayed as a part of object name --- CHANGES | 1 + sphinx/themes/basic/static/searchtools.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index f70a2ecabf2..d352707329e 100644 --- a/CHANGES +++ b/CHANGES @@ -46,6 +46,7 @@ Bugs fixed * #10031: py domain: Fix spurious whitespace in unparsing various operators (``+``, ``-``, ``~``, and ``**``). Patch by Adam Turner. * #10460: logging: Always show node source locations as absolute paths. +* HTML Search: HTML tags are displayed as a part of object name * #10520: HTML Theme: Fix use of sidebar classes in ``agogo.css_t``. * #6679: HTML Theme: Fix inclusion of hidden toctrees in the agogo theme. * #10566: HTML Theme: Fix enable_search_shortcuts does not work diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js index 5ed91c92d55..bd04b049087 100644 --- a/sphinx/themes/basic/static/searchtools.js +++ b/sphinx/themes/basic/static/searchtools.js @@ -88,7 +88,7 @@ const _displayItem = (item, highlightTerms, searchTerms) => { linkEl.href = linkUrl + "?" + params.toString() + anchor; linkEl.innerHTML = title; if (descr) - listItem.appendChild(document.createElement("span")).innerText = + listItem.appendChild(document.createElement("span")).innerHTML = " (" + descr + ")"; else if (showSearchSummary) fetch(requestUrl) From 50897f0cc248241067d520fede5e5b9f6aca0175 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 26 Jun 2022 23:19:14 +0900 Subject: [PATCH 2/4] HTML Search: search snipets should not be folded --- CHANGES | 1 + sphinx/themes/basic/static/searchtools.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index d352707329e..dea7f94089d 100644 --- a/CHANGES +++ b/CHANGES @@ -47,6 +47,7 @@ Bugs fixed ``-``, ``~``, and ``**``). Patch by Adam Turner. * #10460: logging: Always show node source locations as absolute paths. * HTML Search: HTML tags are displayed as a part of object name +* HTML Search: search snipets should not be folded * #10520: HTML Theme: Fix use of sidebar classes in ``agogo.css_t``. * #6679: HTML Theme: Fix inclusion of hidden toctrees in the agogo theme. * #10566: HTML Theme: Fix enable_search_shortcuts does not work diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js index bd04b049087..563e50af76a 100644 --- a/sphinx/themes/basic/static/searchtools.js +++ b/sphinx/themes/basic/static/searchtools.js @@ -519,7 +519,7 @@ const Search = { let summary = document.createElement("p"); summary.classList.add("context"); - summary.innerText = top + text.substr(startWithContext, 240).trim() + tail; + summary.textContent = top + text.substr(startWithContext, 240).trim() + tail; highlightWords.forEach((highlightWord) => _highlightText(summary, highlightWord, "highlighted") From 6ed7405cd9da2ba78f54f90e2decf895cbc25bf2 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 26 Jun 2022 23:22:39 +0900 Subject: [PATCH 3/4] HTML Search: Minor errors are emitted on fetching search snipets --- CHANGES | 1 + sphinx/themes/basic/static/searchtools.js | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index dea7f94089d..5692d38f112 100644 --- a/CHANGES +++ b/CHANGES @@ -48,6 +48,7 @@ Bugs fixed * #10460: logging: Always show node source locations as absolute paths. * HTML Search: HTML tags are displayed as a part of object name * HTML Search: search snipets should not be folded +* HTML Search: Minor errors are emitted on fetching search snipets * #10520: HTML Theme: Fix use of sidebar classes in ``agogo.css_t``. * #6679: HTML Theme: Fix inclusion of hidden toctrees in the agogo theme. * #10566: HTML Theme: Fix enable_search_shortcuts does not work diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js index 563e50af76a..f656da73b98 100644 --- a/sphinx/themes/basic/static/searchtools.js +++ b/sphinx/themes/basic/static/searchtools.js @@ -155,9 +155,7 @@ const Search = { _pulse_status: -1, htmlToText: (htmlString) => { - const htmlElement = document - .createRange() - .createContextualFragment(htmlString); + const htmlElement = new DOMParser().parseFromString(htmlString, 'text/html'); htmlElement.querySelectorAll(".headerlink").forEach((el) => el.parentNode.removeChild(el)); const docContent = htmlElement.querySelector('[role="main"]'); if (docContent !== undefined) return docContent.textContent; From 4dd09eba4d8e4a2cfc1e971ceac3c9081eed9b04 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 26 Jun 2022 23:21:29 +0900 Subject: [PATCH 4/4] HTML Search: refactoring --- CHANGES | 1 + sphinx/themes/basic/static/searchtools.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 5692d38f112..3efd01c3ae1 100644 --- a/CHANGES +++ b/CHANGES @@ -49,6 +49,7 @@ Bugs fixed * HTML Search: HTML tags are displayed as a part of object name * HTML Search: search snipets should not be folded * HTML Search: Minor errors are emitted on fetching search snipets +* HTML Search: The markers for header links are shown in the search result * #10520: HTML Theme: Fix use of sidebar classes in ``agogo.css_t``. * #6679: HTML Theme: Fix inclusion of hidden toctrees in the agogo theme. * #10566: HTML Theme: Fix enable_search_shortcuts does not work diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js index f656da73b98..f2fb7d5cf7e 100644 --- a/sphinx/themes/basic/static/searchtools.js +++ b/sphinx/themes/basic/static/searchtools.js @@ -156,7 +156,7 @@ const Search = { htmlToText: (htmlString) => { const htmlElement = new DOMParser().parseFromString(htmlString, 'text/html'); - htmlElement.querySelectorAll(".headerlink").forEach((el) => el.parentNode.removeChild(el)); + htmlElement.querySelectorAll(".headerlink").forEach((el) => { el.remove() }); const docContent = htmlElement.querySelector('[role="main"]'); if (docContent !== undefined) return docContent.textContent; console.warn(