summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;