mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
extlinks: Disable hardcoded links detector by default (refs: #10126)
The hardcoded links detector added since 4.4.0 causes troubles in many projects. Therefore, this disables it by default, and adds a new configuration `extlinks_detect_hardcoded_links` to enable it explicitly.
This commit is contained in:
parent
a0679463a1
commit
c6230dc4db
4
CHANGES
4
CHANGES
@ -7,6 +7,8 @@ Dependencies
|
|||||||
Incompatible changes
|
Incompatible changes
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
|
* #10112: extlinks: Disable hardcoded links detector by default
|
||||||
|
|
||||||
Deprecated
|
Deprecated
|
||||||
----------
|
----------
|
||||||
|
|
||||||
@ -18,6 +20,8 @@ Features added
|
|||||||
* #10260: Enable ``FORCE_COLOR`` and ``NO_COLOR`` for terminal colouring
|
* #10260: Enable ``FORCE_COLOR`` and ``NO_COLOR`` for terminal colouring
|
||||||
* #10234: autosummary: Add "autosummary" CSS class to summary tables
|
* #10234: autosummary: Add "autosummary" CSS class to summary tables
|
||||||
* #10125: extlinks: Improve suggestion message for a reference having title
|
* #10125: extlinks: Improve suggestion message for a reference having title
|
||||||
|
* #10112: extlinks: Add :confval:`extlinks_detect_hardcoded_links` to enable
|
||||||
|
hardcoded links detector feature
|
||||||
* #9494, #9456: html search: Add a config variable
|
* #9494, #9456: html search: Add a config variable
|
||||||
:confval:`html_show_search_summary` to enable/disable the search summaries
|
:confval:`html_show_search_summary` to enable/disable the search summaries
|
||||||
* #9337: HTML theme, add option ``enable_search_shortcuts`` that enables :kbd:'/' as
|
* #9337: HTML theme, add option ``enable_search_shortcuts`` that enables :kbd:'/' as
|
||||||
|
@ -59,3 +59,11 @@ The extension adds a config value:
|
|||||||
|
|
||||||
Since links are generated from the role in the reading stage, they appear as
|
Since links are generated from the role in the reading stage, they appear as
|
||||||
ordinary links to e.g. the ``linkcheck`` builder.
|
ordinary links to e.g. the ``linkcheck`` builder.
|
||||||
|
|
||||||
|
.. confval:: extlinks_detect_hardcoded_links
|
||||||
|
|
||||||
|
If enabled, extlinks emits a warning if a hardcoded link is replaceable
|
||||||
|
by an extlink, and suggests a replacement via warning. It defaults to
|
||||||
|
``False``.
|
||||||
|
|
||||||
|
.. versionadded:: 4.5
|
||||||
|
@ -47,6 +47,9 @@ class ExternalLinksChecker(SphinxPostTransform):
|
|||||||
default_priority = 500
|
default_priority = 500
|
||||||
|
|
||||||
def run(self, **kwargs: Any) -> None:
|
def run(self, **kwargs: Any) -> None:
|
||||||
|
if not self.config.extlinks_detect_hardcoded_links:
|
||||||
|
return
|
||||||
|
|
||||||
for refnode in self.document.findall(nodes.reference):
|
for refnode in self.document.findall(nodes.reference):
|
||||||
self.check_uri(refnode)
|
self.check_uri(refnode)
|
||||||
|
|
||||||
@ -121,6 +124,8 @@ def setup_link_roles(app: Sphinx) -> None:
|
|||||||
|
|
||||||
def setup(app: Sphinx) -> Dict[str, Any]:
|
def setup(app: Sphinx) -> Dict[str, Any]:
|
||||||
app.add_config_value('extlinks', {}, 'env')
|
app.add_config_value('extlinks', {}, 'env')
|
||||||
|
app.add_config_value('extlinks_detect_hardcoded_links', False, 'env')
|
||||||
|
|
||||||
app.connect('builder-inited', setup_link_roles)
|
app.connect('builder-inited', setup_link_roles)
|
||||||
app.add_post_transform(ExternalLinksChecker)
|
app.add_post_transform(ExternalLinksChecker)
|
||||||
return {'version': sphinx.__display_version__, 'parallel_read_safe': True}
|
return {'version': sphinx.__display_version__, 'parallel_read_safe': True}
|
||||||
|
@ -3,3 +3,4 @@ extlinks = {
|
|||||||
'user': ('https://github.com/%s', '@%s'),
|
'user': ('https://github.com/%s', '@%s'),
|
||||||
'repo': ('https://github.com/%s', 'project %s'),
|
'repo': ('https://github.com/%s', 'project %s'),
|
||||||
}
|
}
|
||||||
|
extlinks_detect_hardcoded_links = True
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
extensions = ['sphinx.ext.extlinks']
|
extensions = ['sphinx.ext.extlinks']
|
||||||
extlinks = {'issue': ('https://github.com/sphinx-doc/sphinx/issues/%s', 'issue %s')}
|
extlinks = {'issue': ('https://github.com/sphinx-doc/sphinx/issues/%s', 'issue %s')}
|
||||||
|
extlinks_detect_hardcoded_links = True
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.sphinx('html', testroot='ext-extlinks-hardcoded-urls',
|
||||||
|
confoverrides={'extlinks_detect_hardcoded_links': False})
|
||||||
|
def test_extlinks_detect_candidates(app, warning):
|
||||||
|
app.build()
|
||||||
|
assert warning.getvalue() == ''
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='ext-extlinks-hardcoded-urls')
|
@pytest.mark.sphinx('html', testroot='ext-extlinks-hardcoded-urls')
|
||||||
def test_replaceable_uris_emit_extlinks_warnings(app, warning):
|
def test_replaceable_uris_emit_extlinks_warnings(app, warning):
|
||||||
app.build()
|
app.build()
|
||||||
|
Loading…
Reference in New Issue
Block a user