Skip to content

Commit 8a84d16

Browse files
authored
Merge pull request #9208 from tk0miya/9201_UndefinedError_websupport
Fix #9201: websupport: UndefinedError is raised: 'css_tag' is undefined
2 parents aa9fab5 + fa8212a commit 8a84d16

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Bugs fixed
2424
* #9198: i18n: Babel emits errors when running compile_catalog
2525
* #9205: py domain: The :canonical: option causes "more than one target for
2626
cross-reference" warning
27+
* #9201: websupport: UndefinedError is raised: 'css_tag' is undefined
2728

2829
Testing
2930
--------

sphinx/builders/html/__init__.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,16 +1000,6 @@ def pathto(otheruri: str, resource: bool = False, baseuri: str = default_baseuri
10001000
return uri
10011001
ctx['pathto'] = pathto
10021002

1003-
def css_tag(css: Stylesheet) -> str:
1004-
attrs = []
1005-
for key in sorted(css.attributes):
1006-
value = css.attributes[key]
1007-
if value is not None:
1008-
attrs.append('%s="%s"' % (key, html.escape(value, True)))
1009-
attrs.append('href="%s"' % pathto(css.filename, resource=True))
1010-
return '<link %s />' % ' '.join(attrs)
1011-
ctx['css_tag'] = css_tag
1012-
10131003
def hasdoc(name: str) -> bool:
10141004
if name in self.env.all_docs:
10151005
return True
@@ -1140,6 +1130,26 @@ def convert_html_js_files(app: Sphinx, config: Config) -> None:
11401130
config.html_js_files = html_js_files # type: ignore
11411131

11421132

1133+
def setup_css_tag_helper(app: Sphinx, pagename: str, templatename: str,
1134+
context: Dict, doctree: Node) -> None:
1135+
"""Set up css_tag() template helper.
1136+
1137+
.. note:: This set up function is added to keep compatibility with webhelper.
1138+
"""
1139+
pathto = context.get('pathto')
1140+
1141+
def css_tag(css: Stylesheet) -> str:
1142+
attrs = []
1143+
for key in sorted(css.attributes):
1144+
value = css.attributes[key]
1145+
if value is not None:
1146+
attrs.append('%s="%s"' % (key, html.escape(value, True)))
1147+
attrs.append('href="%s"' % pathto(css.filename, resource=True))
1148+
return '<link %s />' % ' '.join(attrs)
1149+
1150+
context['css_tag'] = css_tag
1151+
1152+
11431153
def setup_js_tag_helper(app: Sphinx, pagename: str, templatename: str,
11441154
context: Dict, doctree: Node) -> None:
11451155
"""Set up js_tag() template helper.
@@ -1347,6 +1357,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
13471357
app.connect('config-inited', validate_html_logo, priority=800)
13481358
app.connect('config-inited', validate_html_favicon, priority=800)
13491359
app.connect('builder-inited', validate_math_renderer)
1360+
app.connect('html-page-context', setup_css_tag_helper)
13501361
app.connect('html-page-context', setup_js_tag_helper)
13511362
app.connect('html-page-context', setup_resource_paths)
13521363

0 commit comments

Comments
 (0)