mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix highlighting
This commit is contained in:
parent
b4276edd84
commit
cc42c551ee
@ -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");
|
||||||
|
Loading…
Reference in New Issue
Block a user