Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions sphinx/themes/basic/static/sphinx_highlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,8 @@ const SphinxHighlight = {
if (!SPHINX_HIGHLIGHT_ENABLED) return; // bail if no highlight

// get and clear terms from localstorage
const url = new URL(window.location);
const highlight =
localStorage.getItem("sphinx_highlight_terms")
|| url.searchParams.get("highlight")
|| "";
const highlight = localStorage.getItem("sphinx_highlight_terms") || "";
localStorage.removeItem("sphinx_highlight_terms");
url.searchParams.delete("highlight");
window.history.replaceState({}, "", url);

// get individual terms from highlight string
const terms = highlight
Expand All @@ -91,11 +85,10 @@ const SphinxHighlight = {
if (terms.length === 0) return; // nothing to do

// There should never be more than one element matching "div.body"
const divBody = document.querySelectorAll("div.body");
const body = divBody.length ? divBody[0] : document.querySelector("body");
window.setTimeout(() => {
const body = document.querySelector("div.body") || document.body;
window.requestAnimationFrame(() => {
terms.forEach((term) => _highlightText(body, term, "highlighted"));
}, 10);
});

const searchBox = document.getElementById("searchbox");
if (searchBox === null) return;
Expand Down
Loading