summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshiftinv <8530778+shiftinv@users.noreply.github.com>2022-07-12 23:51:29 +0200
committerGitHub <noreply@github.com>2022-07-12 22:51:29 +0100
commitede71fd64403290b67a8db75b858df3ae07ca5d4 (patch)
tree5178f3b6b3e9e12557db369156c43da4aeb1c61d
parentb3e03d9d07c5f9624b2a17d66697eca67bfcba20 (diff)
downloadsphinx-git-ede71fd64403290b67a8db75b858df3ae07ca5d4.tar.gz
Fix minor HTML search summary issues (#10548)
-rw-r--r--sphinx/themes/basic/static/searchtools.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js
index ac4d5861f..5ed91c92d 100644
--- a/sphinx/themes/basic/static/searchtools.js
+++ b/sphinx/themes/basic/static/searchtools.js
@@ -158,7 +158,7 @@ const Search = {
const htmlElement = document
.createRange()
.createContextualFragment(htmlString);
- _removeChildren(htmlElement.querySelectorAll(".headerlink"));
+ htmlElement.querySelectorAll(".headerlink").forEach((el) => el.parentNode.removeChild(el));
const docContent = htmlElement.querySelector('[role="main"]');
if (docContent !== undefined) return docContent.textContent;
console.warn(
@@ -504,11 +504,12 @@ const Search = {
* latter for highlighting it.
*/
makeSearchSummary: (htmlText, keywords, highlightWords) => {
- const text = Search.htmlToText(htmlText).toLowerCase();
+ const text = Search.htmlToText(htmlText);
if (text === "") return null;
+ const textLower = text.toLowerCase();
const actualStartPosition = [...keywords]
- .map((k) => text.indexOf(k.toLowerCase()))
+ .map((k) => textLower.indexOf(k.toLowerCase()))
.filter((i) => i > -1)
.slice(-1)[0];
const startWithContext = Math.max(actualStartPosition - 120, 0);
@@ -516,7 +517,7 @@ const Search = {
const top = startWithContext === 0 ? "" : "...";
const tail = startWithContext + 240 < text.length ? "..." : "";
- let summary = document.createElement("div");
+ let summary = document.createElement("p");
summary.classList.add("context");
summary.innerText = top + text.substr(startWithContext, 240).trim() + tail;