@@ -1000,16 +1000,6 @@ def pathto(otheruri: str, resource: bool = False, baseuri: str = default_baseuri
1000
1000
return uri
1001
1001
ctx ['pathto' ] = pathto
1002
1002
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
-
1013
1003
def hasdoc (name : str ) -> bool :
1014
1004
if name in self .env .all_docs :
1015
1005
return True
@@ -1140,6 +1130,26 @@ def convert_html_js_files(app: Sphinx, config: Config) -> None:
1140
1130
config .html_js_files = html_js_files # type: ignore
1141
1131
1142
1132
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
+
1143
1153
def setup_js_tag_helper (app : Sphinx , pagename : str , templatename : str ,
1144
1154
context : Dict , doctree : Node ) -> None :
1145
1155
"""Set up js_tag() template helper.
@@ -1347,6 +1357,7 @@ def setup(app: Sphinx) -> Dict[str, Any]:
1347
1357
app .connect ('config-inited' , validate_html_logo , priority = 800 )
1348
1358
app .connect ('config-inited' , validate_html_favicon , priority = 800 )
1349
1359
app .connect ('builder-inited' , validate_math_renderer )
1360
+ app .connect ('html-page-context' , setup_css_tag_helper )
1350
1361
app .connect ('html-page-context' , setup_js_tag_helper )
1351
1362
app .connect ('html-page-context' , setup_resource_paths )
1352
1363
0 commit comments