|
1 | 1 | import html
|
2 |
| -import docutils.nodes |
3 | 2 | import os
|
4 | 3 | import warnings
|
5 | 4 |
|
| 5 | +import docutils.nodes |
6 | 6 | import sphinx
|
7 | 7 | from sphinx.environment.collectors import EnvironmentCollector
|
8 | 8 | from sphinx.errors import ExtensionError
|
|
13 | 13 |
|
14 | 14 | class BaseURIError(ExtensionError):
|
15 | 15 | """Exception for malformed base URI."""
|
16 |
| - pass |
17 | 16 |
|
18 | 17 |
|
19 | 18 | # https://www.sphinx-doc.org/en/stable/extdev/appapi.html#event-html-collect-pages
|
@@ -167,7 +166,11 @@ def toctree(*args, **kwargs):
|
167 | 166 | # We have to overwrite them here to use our own `pathto` function.
|
168 | 167 | # The code is borrowed exactly from Sphinx 7.2.2, there is no changes.
|
169 | 168 | if sphinx.version_info >= (7, 2):
|
170 |
| - from sphinx.builders.html._assets import _CascadingStyleSheet, _file_checksum, _JavaScript |
| 169 | + from sphinx.builders.html._assets import ( |
| 170 | + _CascadingStyleSheet, |
| 171 | + _file_checksum, |
| 172 | + _JavaScript, |
| 173 | + ) |
171 | 174 |
|
172 | 175 | outdir = app.outdir
|
173 | 176 |
|
@@ -266,14 +269,22 @@ def validate_configs(app, *args, **kwargs):
|
266 | 269 |
|
267 | 270 | Shows a warning if one of the configs is not valid.
|
268 | 271 | """
|
269 |
| - default, rebuild, types = app.config.values.get('notfound_urls_prefix') |
270 |
| - if app.config.notfound_urls_prefix != default: |
271 |
| - if app.config.notfound_urls_prefix and not all([ |
272 |
| - app.config.notfound_urls_prefix.startswith('/'), |
273 |
| - app.config.notfound_urls_prefix.endswith('/'), |
274 |
| - ]): |
275 |
| - message = 'notfound_urls_prefix should start and end with "/" (slash)' |
276 |
| - warnings.warn(message, UserWarning, stacklevel=2) |
| 272 | + notfound_urls_prefix = app.config.notfound_urls_prefix |
| 273 | + default = ( |
| 274 | + app.config.values.get("notfound_urls_prefix").default |
| 275 | + if sphinx.version_info >= (7, 2) |
| 276 | + else app.config.values.get("notfound_urls_prefix")[0] |
| 277 | + ) |
| 278 | + |
| 279 | + if ( |
| 280 | + notfound_urls_prefix != default |
| 281 | + and notfound_urls_prefix |
| 282 | + and not ( |
| 283 | + notfound_urls_prefix.startswith("/") or notfound_urls_prefix.endswith("/") |
| 284 | + ) |
| 285 | + ): |
| 286 | + message = 'notfound_urls_prefix should start and end with "/" (slash)' |
| 287 | + warnings.warn(message, UserWarning, stacklevel=2) |
277 | 288 |
|
278 | 289 |
|
279 | 290 | def setup(app):
|
|
0 commit comments