@@ -916,21 +916,21 @@ def add_post_transform(self, transform: "Type[Transform]") -> None:
916
916
"""
917
917
self .registry .add_post_transform (transform )
918
918
919
- def add_javascript (self , filename : str , ** kwargs : str ) -> None :
919
+ def add_javascript (self , filename : str , ** kwargs : Any ) -> None :
920
920
"""An alias of :meth:`add_js_file`."""
921
921
warnings .warn ('The app.add_javascript() is deprecated. '
922
922
'Please use app.add_js_file() instead.' ,
923
923
RemovedInSphinx40Warning , stacklevel = 2 )
924
924
self .add_js_file (filename , ** kwargs )
925
925
926
- def add_js_file (self , filename : str , ** kwargs : str ) -> None :
926
+ def add_js_file (self , filename : str , priority : int = 500 , ** kwargs : Any ) -> None :
927
927
"""Register a JavaScript file to include in the HTML output.
928
928
929
929
Add *filename* to the list of JavaScript files that the default HTML
930
- template will include. The filename must be relative to the HTML
931
- static path , or a full URI with scheme. If the keyword argument
932
- ``body`` is given, its value will be added between the
933
- ``<script>`` tags. Extra keyword arguments are included as
930
+ template will include in order of *priority* (ascending). The filename
931
+ must be relative to the HTML static path , or a full URI with scheme.
932
+ If the keyword argument ``body`` is given, its value will be added
933
+ between the ``<script>`` tags. Extra keyword arguments are included as
934
934
attributes of the ``<script>`` tag.
935
935
936
936
Example::
@@ -944,23 +944,38 @@ def add_js_file(self, filename: str, **kwargs: str) -> None:
944
944
app.add_js_file(None, body="var myVariable = 'foo';")
945
945
# => <script>var myVariable = 'foo';</script>
946
946
947
+ .. list-table:: priority range for JavaScript files
948
+ :widths: 20,80
949
+
950
+ * - Priority
951
+ - Main purpose in Sphinx
952
+ * - 200
953
+ - default priority for built-in JavaScript files
954
+ * - 500
955
+ - default priority for extensions
956
+ * - 800
957
+ - default priority for :confval:`html_js_files`
958
+
947
959
.. versionadded:: 0.5
948
960
949
961
.. versionchanged:: 1.8
950
962
Renamed from ``app.add_javascript()``.
951
963
And it allows keyword arguments as attributes of script tag.
964
+
965
+ .. versionchanged:: 3.5
966
+ Take priority argument.
952
967
"""
953
- self .registry .add_js_file (filename , ** kwargs )
968
+ self .registry .add_js_file (filename , priority = priority , ** kwargs )
954
969
if hasattr (self .builder , 'add_js_file' ):
955
- self .builder .add_js_file (filename , ** kwargs ) # type: ignore
970
+ self .builder .add_js_file (filename , priority = priority , ** kwargs ) # type: ignore
956
971
957
- def add_css_file (self , filename : str , ** kwargs : str ) -> None :
972
+ def add_css_file (self , filename : str , priority : int = 500 , ** kwargs : Any ) -> None :
958
973
"""Register a stylesheet to include in the HTML output.
959
974
960
975
Add *filename* to the list of CSS files that the default HTML template
961
- will include. The filename must be relative to the HTML static path,
962
- or a full URI with scheme. The keyword arguments are also accepted for
963
- attributes of ``<link>`` tag.
976
+ will include in order of *priority* (ascending). The filename must be
977
+ relative to the HTML static path, or a full URI with scheme. The
978
+ eyword arguments are also accepted for attributes of ``<link>`` tag.
964
979
965
980
Example::
966
981
@@ -975,6 +990,16 @@ def add_css_file(self, filename: str, **kwargs: str) -> None:
975
990
# => <link rel="alternate stylesheet" href="_static/fancy.css"
976
991
# type="text/css" title="fancy" />
977
992
993
+ .. list-table:: priority range for CSS files
994
+ :widths: 20,80
995
+
996
+ * - Priority
997
+ - Main purpose in Sphinx
998
+ * - 500
999
+ - default priority for extensions
1000
+ * - 800
1001
+ - default priority for :confval:`html_css_files`
1002
+
978
1003
.. versionadded:: 1.0
979
1004
980
1005
.. versionchanged:: 1.6
@@ -987,11 +1012,14 @@ def add_css_file(self, filename: str, **kwargs: str) -> None:
987
1012
.. versionchanged:: 1.8
988
1013
Renamed from ``app.add_stylesheet()``.
989
1014
And it allows keyword arguments as attributes of link tag.
1015
+
1016
+ .. versionchanged:: 3.5
1017
+ Take priority argument.
990
1018
"""
991
1019
logger .debug ('[app] adding stylesheet: %r' , filename )
992
- self .registry .add_css_files (filename , ** kwargs )
1020
+ self .registry .add_css_files (filename , priority = priority , ** kwargs )
993
1021
if hasattr (self .builder , 'add_css_file' ):
994
- self .builder .add_css_file (filename , ** kwargs ) # type: ignore
1022
+ self .builder .add_css_file (filename , priority = priority , ** kwargs ) # type: ignore
995
1023
996
1024
def add_stylesheet (self , filename : str , alternate : bool = False , title : str = None
997
1025
) -> None :
@@ -1000,7 +1028,7 @@ def add_stylesheet(self, filename: str, alternate: bool = False, title: str = No
1000
1028
'Please use app.add_css_file() instead.' ,
1001
1029
RemovedInSphinx40Warning , stacklevel = 2 )
1002
1030
1003
- attributes = {} # type: Dict[str, str ]
1031
+ attributes = {} # type: Dict[str, Any ]
1004
1032
if alternate :
1005
1033
attributes ['rel' ] = 'alternate stylesheet'
1006
1034
else :
0 commit comments