mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #9201: websupport: UndefinedError is raised: 'css_tag' is undefined
This commit is contained in:
1
CHANGES
1
CHANGES
@@ -24,6 +24,7 @@ Bugs fixed
|
|||||||
* #9198: i18n: Babel emits errors when running compile_catalog
|
* #9198: i18n: Babel emits errors when running compile_catalog
|
||||||
* #9205: py domain: The :canonical: option causes "more than one target for
|
* #9205: py domain: The :canonical: option causes "more than one target for
|
||||||
cross-reference" warning
|
cross-reference" warning
|
||||||
|
* #9201: websupport: UndefinedError is raised: 'css_tag' is undefined
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
|||||||
@@ -1000,16 +1000,6 @@ class StandaloneHTMLBuilder(Builder):
|
|||||||
return uri
|
return uri
|
||||||
ctx['pathto'] = pathto
|
ctx['pathto'] = pathto
|
||||||
|
|
||||||
def css_tag(css: Stylesheet) -> str:
|
|
||||||
attrs = []
|
|
||||||
for key in sorted(css.attributes):
|
|
||||||
value = css.attributes[key]
|
|
||||||
if value is not None:
|
|
||||||
attrs.append('%s="%s"' % (key, html.escape(value, True)))
|
|
||||||
attrs.append('href="%s"' % pathto(css.filename, resource=True))
|
|
||||||
return '<link %s />' % ' '.join(attrs)
|
|
||||||
ctx['css_tag'] = css_tag
|
|
||||||
|
|
||||||
def hasdoc(name: str) -> bool:
|
def hasdoc(name: str) -> bool:
|
||||||
if name in self.env.all_docs:
|
if name in self.env.all_docs:
|
||||||
return True
|
return True
|
||||||
@@ -1140,6 +1130,26 @@ def convert_html_js_files(app: Sphinx, config: Config) -> None:
|
|||||||
config.html_js_files = html_js_files # type: ignore
|
config.html_js_files = html_js_files # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
def setup_css_tag_helper(app: Sphinx, pagename: str, templatename: str,
|
||||||
|
context: Dict, doctree: Node) -> None:
|
||||||
|
"""Set up css_tag() template helper.
|
||||||
|
|
||||||
|
.. note:: This set up function is added to keep compatibility with webhelper.
|
||||||
|
"""
|
||||||
|
pathto = context.get('pathto')
|
||||||
|
|
||||||
|
def css_tag(css: Stylesheet) -> str:
|
||||||
|
attrs = []
|
||||||
|
for key in sorted(css.attributes):
|
||||||
|
value = css.attributes[key]
|
||||||
|
if value is not None:
|
||||||
|
attrs.append('%s="%s"' % (key, html.escape(value, True)))
|
||||||
|
attrs.append('href="%s"' % pathto(css.filename, resource=True))
|
||||||
|
return '<link %s />' % ' '.join(attrs)
|
||||||
|
|
||||||
|
context['css_tag'] = css_tag
|
||||||
|
|
||||||
|
|
||||||
def setup_js_tag_helper(app: Sphinx, pagename: str, templatename: str,
|
def setup_js_tag_helper(app: Sphinx, pagename: str, templatename: str,
|
||||||
context: Dict, doctree: Node) -> None:
|
context: Dict, doctree: Node) -> None:
|
||||||
"""Set up js_tag() template helper.
|
"""Set up js_tag() template helper.
|
||||||
@@ -1347,6 +1357,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
|
|||||||
app.connect('config-inited', validate_html_logo, priority=800)
|
app.connect('config-inited', validate_html_logo, priority=800)
|
||||||
app.connect('config-inited', validate_html_favicon, priority=800)
|
app.connect('config-inited', validate_html_favicon, priority=800)
|
||||||
app.connect('builder-inited', validate_math_renderer)
|
app.connect('builder-inited', validate_math_renderer)
|
||||||
|
app.connect('html-page-context', setup_css_tag_helper)
|
||||||
app.connect('html-page-context', setup_js_tag_helper)
|
app.connect('html-page-context', setup_js_tag_helper)
|
||||||
app.connect('html-page-context', setup_resource_paths)
|
app.connect('html-page-context', setup_resource_paths)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user