From 2ff3232cac2278f22624a0a2e8daf2280b14912c Mon Sep 17 00:00:00 2001 From: Yuriy Andamasov Date: Wed, 15 Apr 2026 12:31:26 +0300 Subject: refactor: use builder-inited hook for WebP image type override Replaces class-level patching of StandaloneHTMLBuilder/DirectoryHTMLBuilder with a builder-inited event hook that only modifies html, dirhtml, and readthedocs builders. This avoids unintentionally affecting EPUB or HTMLHelp builders that inherit from StandaloneHTMLBuilder. Co-Authored-By: Claude Opus 4.6 (1M context) --- docs/conf.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'docs/conf.py') diff --git a/docs/conf.py b/docs/conf.py index eacec2c7..dc24ba85 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -198,16 +198,17 @@ texinfo_documents = [ ] +def _prefer_webp(app): + """Add WebP to front of supported types for HTML/dirhtml builders only.""" + if app.builder.name in ('html', 'dirhtml', 'readthedocs'): + app.builder.supported_image_types = [ + 'image/webp', + 'image/svg+xml', + 'image/png', + 'image/gif', + 'image/jpeg', + ] + + def setup(app): - # Prefer WebP for HTML output; LaTeX keeps its default (PDF/PNG/JPEG) - webp_types = [ - 'image/webp', - 'image/svg+xml', - 'image/png', - 'image/gif', - 'image/jpeg', - ] - from sphinx.builders.html import StandaloneHTMLBuilder - StandaloneHTMLBuilder.supported_image_types = webp_types - from sphinx.builders.dirhtml import DirectoryHTMLBuilder - DirectoryHTMLBuilder.supported_image_types = webp_types \ No newline at end of file + app.connect('builder-inited', _prefer_webp) -- cgit v1.2.3