From ede71fd64403290b67a8db75b858df3ae07ca5d4 Mon Sep 17 00:00:00 2001 From: shiftinv <8530778+shiftinv@users.noreply.github.com> Date: Tue, 12 Jul 2022 23:51:29 +0200 Subject: [PATCH] Fix minor HTML search summary issues (#10548) --- sphinx/themes/basic/static/searchtools.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sphinx/themes/basic/static/searchtools.js b/sphinx/themes/basic/static/searchtools.js index ac4d5861f95..5ed91c92d55 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;