Skip to content

Commit

Permalink
apply review suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Oleg Hoefling <oleg.hoefling@gmail.com>
  • Loading branch information
hoefling committed Nov 12, 2021
1 parent bc5dd0e commit 7b318d8
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions sphinx/ext/extlinks.py
Expand Up @@ -42,6 +42,8 @@
from sphinx.util.nodes import split_explicit_title
from sphinx.util.typing import RoleFunction

logger = logging.getLogger(__name__)


class ExternalLinksChecker(SphinxPostTransform):
"""
Expand All @@ -50,7 +52,7 @@ class ExternalLinksChecker(SphinxPostTransform):
We treat each ``reference`` node without ``internal`` attribute as an external link.
"""

default_priority = 900
default_priority = 100

def run(self, **kwargs: Any) -> None:
for refnode in self.document.traverse(nodes.reference):
Expand All @@ -65,21 +67,18 @@ def check_uri(self, refnode: nodes.reference) -> None:
return

uri = refnode['refuri']
lineno = sphinx.util.nodes.get_node_line(refnode)
extlinks_config = getattr(self.app.config, 'extlinks', dict())

for alias, (base_uri, caption) in extlinks_config.items():
for alias, (base_uri, caption) in self.app.config.extlinks.items():
uri_pattern = re.compile(base_uri.replace('%s', '(?P<value>.+)'))
match = uri_pattern.match(uri)
if match and match.groupdict().get('value'):
# build a replacement suggestion
replacement = f":{alias}:`{match.groupdict().get('value')}`"
location = (self.env.docname, lineno)
logger.warning(
'hardcoded link %r could be replaced by an extlink (try using %r instead)',
__('hardcoded link %r could be replaced by an extlink (try using %r instead)'),
uri,
replacement,
location=location,
location=refnode,
)


Expand Down

0 comments on commit 7b318d8

Please sign in to comment.