mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Remove hidden pass-through calls when adding asset files
``Sphinx.add_css_file()`` called ``Builder.add_css_file()`` and``Sphinx.add_js_file()`` called ``Builder.add_js_file()``.
This commit is contained in:
parent
916d8274bb
commit
fa17437254
@ -1030,9 +1030,6 @@ class Sphinx:
|
||||
kwargs['defer'] = 'defer'
|
||||
|
||||
self.registry.add_js_file(filename, priority=priority, **kwargs)
|
||||
if hasattr(self, 'builder') and hasattr(self.builder, 'add_js_file'):
|
||||
self.builder.add_js_file(filename,
|
||||
priority=priority, **kwargs)
|
||||
|
||||
def add_css_file(self, filename: str, priority: int = 500, **kwargs: Any) -> None:
|
||||
"""Register a stylesheet to include in the HTML output.
|
||||
@ -1093,9 +1090,6 @@ class Sphinx:
|
||||
"""
|
||||
logger.debug('[app] adding stylesheet: %r', filename)
|
||||
self.registry.add_css_files(filename, priority=priority, **kwargs)
|
||||
if hasattr(self, 'builder') and hasattr(self.builder, 'add_css_file'):
|
||||
self.builder.add_css_file(filename,
|
||||
priority=priority, **kwargs)
|
||||
|
||||
def add_latex_package(self, packagename: str, options: str | None = None,
|
||||
after_hyperref: bool = False) -> None:
|
||||
|
@ -498,9 +498,15 @@ class StandaloneHTMLBuilder(Builder):
|
||||
rellinks.append((indexname, indexcls.localname,
|
||||
'', indexcls.shortname))
|
||||
|
||||
# add assets registered after ``Builder.init()``.
|
||||
for css_filename, attrs in self.app.registry.css_files:
|
||||
self.add_css_file(css_filename, **attrs)
|
||||
for js_filename, attrs in self.app.registry.js_files:
|
||||
self.add_js_file(js_filename or '', **attrs)
|
||||
|
||||
# back up _css_files and _js_files to allow adding CSS/JS files to a specific page.
|
||||
self._orig_css_files = list(self._css_files)
|
||||
self._orig_js_files = list(self._js_files)
|
||||
self._orig_css_files = list(dict.fromkeys(self._css_files))
|
||||
self._orig_js_files = list(dict.fromkeys(self._js_files))
|
||||
styles = list(self._get_style_filenames())
|
||||
|
||||
self.globalcontext = {
|
||||
|
@ -14,6 +14,7 @@ from docutils import nodes
|
||||
|
||||
import sphinx
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.builders.html import StandaloneHTMLBuilder
|
||||
from sphinx.domains.math import MathDomain
|
||||
from sphinx.errors import ExtensionError
|
||||
from sphinx.locale import _
|
||||
@ -79,6 +80,7 @@ def install_mathjax(app: Sphinx, pagename: str, templatename: str, context: dict
|
||||
'mathjax extension to work')
|
||||
|
||||
domain = cast(MathDomain, app.env.get_domain('math'))
|
||||
builder = cast(StandaloneHTMLBuilder, app.builder)
|
||||
if app.registry.html_assets_policy == 'always' or domain.has_equations(pagename):
|
||||
# Enable mathjax only if equations exists
|
||||
if app.config.mathjax2_config:
|
||||
@ -87,10 +89,10 @@ def install_mathjax(app: Sphinx, pagename: str, templatename: str, context: dict
|
||||
'mathjax_config/mathjax2_config does not work '
|
||||
'for the current MathJax version, use mathjax3_config instead')
|
||||
body = 'MathJax.Hub.Config(%s)' % json.dumps(app.config.mathjax2_config)
|
||||
app.add_js_file(None, type='text/x-mathjax-config', body=body)
|
||||
builder.add_js_file('', type='text/x-mathjax-config', body=body)
|
||||
if app.config.mathjax3_config:
|
||||
body = 'window.MathJax = %s' % json.dumps(app.config.mathjax3_config)
|
||||
app.add_js_file(None, body=body)
|
||||
builder.add_js_file('', body=body)
|
||||
|
||||
options = {}
|
||||
if app.config.mathjax_options:
|
||||
@ -102,7 +104,7 @@ def install_mathjax(app: Sphinx, pagename: str, templatename: str, context: dict
|
||||
else:
|
||||
# Load other MathJax via "async" method
|
||||
options['async'] = 'async'
|
||||
app.add_js_file(app.config.mathjax_path, **options)
|
||||
builder.add_js_file(app.config.mathjax_path, **options)
|
||||
|
||||
|
||||
def setup(app: Sphinx) -> dict[str, Any]:
|
||||
|
Loading…
Reference in New Issue
Block a user