Skip to content

Commit

Permalink
Do not use query components in URLs for assets in EPUB rendering
Browse files Browse the repository at this point in the history
If the EPUB builder is detected, do not add checksums in a query
component to the URL of css and js assets.

The XHTML in EPUBs does not allow the use of query components in
relative URLs.
The checksumming of assets, introduced in
ae20669 unconditionally adds a query
component for the checksum, which breaks rendering on many enduser
devices (tested on e.g. Kindle Paperwhite 3, Kobo Aura H2O Edition 2).

Fixes sphinx-doc#11598

Signed-off-by: David Runge <dave@sleepmap.de>
  • Loading branch information
dvzrv committed Nov 23, 2023
1 parent 3596590 commit 37ff359
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Bugs fixed
package (triggered if using ``fontenc`` with ``T2A`` option and document
language is not a Cyrillic one).
Patch by Jean-François B.
* #11598: Do not use query components in URLs for assets in EPUB rendering.
Patch by David Runge.

Testing
-------
Expand Down
8 changes: 6 additions & 2 deletions sphinx/builders/html/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,9 @@ def css_tag(css: _CascadingStyleSheet) -> str:
attrs.append(f'{key}="{html.escape(value, quote=True)}"')
uri = pathto(os.fspath(css.filename), resource=True)
if checksum := _file_checksum(outdir, css.filename):
uri += f'?v={checksum}'
# the EPUB format does not allow the use of query components
if self.name != 'epub':
uri += f'?v={checksum}'
return f'<link {" ".join(sorted(attrs))} href="{uri}" />'

ctx['css_tag'] = css_tag
Expand Down Expand Up @@ -1092,7 +1094,9 @@ def js_tag(js: _JavaScript | str) -> str:
# https://github.com/sphinx-doc/sphinx/issues/11658
pass
elif checksum := _file_checksum(outdir, js.filename):
uri += f'?v={checksum}'
# the EPUB format does not allow the use of query components
if self.name != 'epub':
uri += f'?v={checksum}'
if attrs:
return f'<script {" ".join(sorted(attrs))} src="{uri}"></script>'
return f'<script src="{uri}"></script>'
Expand Down

0 comments on commit 37ff359

Please sign in to comment.