From 9a8aa16dfad3bb24c4c8c68a2c4100937176336d Mon Sep 17 00:00:00 2001 From: Christian Roth Date: Fri, 26 Nov 2021 18:14:29 +0100 Subject: [PATCH] linkcheck: exclude links from matched documents --- sphinx/builders/linkcheck.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py index 8b08c546bb3..0b9eaf2098d 100644 --- a/sphinx/builders/linkcheck.py +++ b/sphinx/builders/linkcheck.py @@ -248,6 +248,8 @@ def __init__(self, env: BuildEnvironment, config: Config, rqueue: Queue, self.anchors_ignore = [re.compile(x) for x in self.config.linkcheck_anchors_ignore] + self.documents_ignore = [re.compile(doc) + for doc in self.config.linkcheck_documents_ignore] self.auth = [(re.compile(pattern), auth_info) for pattern, auth_info in self.config.linkcheck_auth] @@ -378,6 +380,11 @@ def allowed_redirect(url: str, new_url: str) -> bool: def check(docname: str) -> Tuple[str, str, int]: # check for various conditions without bothering the network + + for doc_matcher in self.documents_ignore: + if doc_matcher.match(docname): + return 'unchecked', '', 0 + if len(uri) == 0 or uri.startswith(('#', 'mailto:', 'tel:')): return 'unchecked', '', 0 elif not uri.startswith(('http:', 'https:')): @@ -554,6 +561,7 @@ def setup(app: Sphinx) -> Dict[str, Any]: # Anchors starting with ! are ignored since they are # commonly used for dynamic pages app.add_config_value('linkcheck_anchors_ignore', ["^!"], None) + app.add_config_value('linkcheck_documents_ignore', [], None) app.add_config_value('linkcheck_rate_limit_timeout', 300.0, None) app.add_event('linkcheck-process-uri')