Skip to content

Commit

Permalink
linkcheck: exclude links from matched documents
Browse files Browse the repository at this point in the history
  • Loading branch information
croth1 committed Nov 26, 2021
1 parent 2b0ba50 commit a837630
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions sphinx/builders/linkcheck.py
Expand Up @@ -378,6 +378,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]

Expand Down Expand Up @@ -519,6 +521,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:')):
Expand Down Expand Up @@ -709,6 +716,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')
Expand Down

0 comments on commit a837630

Please sign in to comment.