You can use Sphinx's application API and event handling features to determine which builder that is currently running. See https://www.sphinx-doc.org/en/master/extdev/appapi.html.
Here is what a handler for the source-read
event could look like:
def workaround(app, docname, source):
if app.builder.name == "html":
my_workaround_for_html_docs()
else:
my_workaround_for_the_rest_of_the_formats()
def setup(app):
app.connect("source-read", workaround)
Some other event might be more appropriate for your specific case.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…