diff --git a/source/_extensions/redown.py b/source/_extensions/redown.py index 0df2892cf1..5f06d5084b 100644 --- a/source/_extensions/redown.py +++ b/source/_extensions/redown.py @@ -16,6 +16,40 @@ from dataclasses import dataclass +LINK_CORE = r""" + \[ (?P[^\[\]]*?) \] # link brackets + text w/o brackets - allows spaces in text + \( + (?P + \S+? # link start + (?: + \( [^()\s]*? \) # nested parens + text w/o parens - matches `initialize(boolean)` + [^()\s]*? # more text - matches `initialize(boolean)abc` + )*? # allow none (or multiple?) + ) + \) + """ + +ROLE_LINK_RE = re.compile( + r""" + (? + :(?:.\w+?:)+? # role(s) - matches :py:func: or :mod: or :class: + ) + """ + + LINK_CORE, + re.VERBOSE, # whitespace and comments are ignored +) + +LINK_RE = re.compile( + r""" + (? str: """21""" @@ -96,17 +130,15 @@ class Chunk: text = heading("####", "~") "redown, redown, redown, redown" - role_links = lambda: re.sub( - r"(:.\w+?:)\[([^\]\n]+?)\]\(([^)]+?)\)", - r"\1`\2 <\3>` ", + role_links = lambda: ROLE_LINK_RE.sub( + lambda m: f"{m.group('role')}`{(t:=m.group('text'))}{' ' if len(t) else ''}<{m.group('link')}>`", text, ) text = role_links() "redown, redown, redown, redown" - links = lambda: re.sub( - r"(?`__", + links = lambda: LINK_RE.sub( + lambda m: f"`{(t:=m.group('text'))}{' ' if len(t) else ''}<{m.group('link')}>`__", text, ) text = links() diff --git a/source/conf.py b/source/conf.py index 6f4db9c304..2f5463451d 100644 --- a/source/conf.py +++ b/source/conf.py @@ -162,7 +162,6 @@ linkcheck_anchors_ignore_for_url = [ r".*github.com.*", - r".*github.wpilib.org/allwpilib/docs/development/java/.*", # until #2695 is fixed r".*ni.com/en/support/downloads/drivers/download.frc-game-tools.html.*", ]