Fix highlighting

This commit is contained in:
Adam Turner 2022-04-09 20:12:15 +01:00
parent b4276edd84
commit cc42c551ee

View File

@ -130,18 +130,15 @@ const Documentation = {
* highlight the search words provided in the url in the text * highlight the search words provided in the url in the text
*/ */
highlightSearchWords: () => { highlightSearchWords: () => {
const highlight = new URLSearchParams(window.location.search).get( const highlight = new URLSearchParams(window.location.search).get("highlight") || "";
"highlight" const terms = highlight.toLowerCase().split(/\s+/);
);
const terms = highlight ? highlight.split(/\s+/) : [];
if (terms.length === 0) return; // nothing to do if (terms.length === 0) return; // nothing to do
let body = document.querySelectorAll("div.body"); // There should never be more than one element matching "div.body"
if (!body.length) body = document.querySelector("body"); const divBody = document.querySelectorAll("div.body");
const body = divBody.length ? divBody[0] : document.querySelector("body");
window.setTimeout(() => { window.setTimeout(() => {
terms.forEach((term) => terms.forEach((term) => _highlightText(body, term, "highlighted"));
_highlightText(body, term.toLowerCase(), "highlighted")
);
}, 10); }, 10);
const searchBox = document.getElementById("searchbox"); const searchBox = document.getElementById("searchbox");