Skip to content

Commit

Permalink
Merge pull request #95 from easyops-cn/steve/fix-marking-in-code-blocks
Browse files Browse the repository at this point in the history
fix: fix an issue of highlighting in code blocks
  • Loading branch information
weareoutman authored Jun 5, 2021
2 parents 841a82a + 3378b9c commit f11bb76
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/client/theme/SearchBar/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,19 @@ export default function SearchBar({
if (keywords.length === 0) {
return;
}
const root = document.querySelector("article");
if (!root) {
return;
}
const mark = new Mark(root);
mark.unmark();
mark.mark(keywords);
// A workaround to fix an issue of highlighting in code blocks.
// See https://github.com/easyops-cn/docusaurus-search-local/issues/92
// Code blocks will be re-rendered after this `useEffect` ran.
// So we make the marking run after a macro task.
setTimeout(() => {
const root = document.querySelector("article");
if (!root) {
return;
}
const mark = new Mark(root);
mark.unmark();
mark.mark(keywords);
});
}, [location.search]);

const onInputFocus = useCallback(() => {
Expand Down

0 comments on commit f11bb76

Please sign in to comment.