sphinx
sphinx copied to clipboard
highlightSearchWords() is not called after fragments are loaded via AJAX
Describe the bug
When I build Sphinx' own documentation locally, and search for example, search results look like this:

Only if I go to browser console and call SphinxHighlight.highlightSearchWords(), it starts looking like this:

highlightSearchWords() is called on DOMContentLoaded event, but page fragments are loaded separately after that event.
How to Reproduce
$ git clone https://github.com/sphinx-doc/sphinx.git
$ cd sphinx
$ python3 ./sphinx/cmd/build.py -T doc build/html/
$ cd build/html
$ python3 -m http.server
$ # open http://127.0.0.1:8000/search.html?q=example
Expected behavior
Search terms are highlighted after all page fragments are loaded.
Your project
Sphinx itself
Screenshots
No response
OS
Linux
Python version
3.10.7
Sphinx version
5.2.0.post1 and master
Sphinx extensions
No response
Extra tools
No response
Additional context
No response