Skip to content

Commit

Permalink
Fix redown link parsing (#2707)
Browse files Browse the repository at this point in the history
remove anchor link check exclusion
  • Loading branch information
TheTripleV authored Aug 20, 2024
1 parent f54f50c commit 8d3c821
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
44 changes: 38 additions & 6 deletions source/_extensions/redown.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,40 @@
from dataclasses import dataclass


LINK_CORE = r"""
\[ (?P<text>[^\[\]]*?) \] # link brackets + text w/o brackets - allows spaces in text
\(
(?P<link>
\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) # not alphanum - prevents matching inline code ``initialize[0](0)``
(?P<role>
:(?:.\w+?:)+? # role(s) - matches :py:func: or :mod: or :class:
)
"""
+ LINK_CORE,
re.VERBOSE, # whitespace and comments are ignored
)

LINK_RE = re.compile(
r"""
(?<!\w) # not alphanum - prevents matching inline code ``initialize[0](0)``
(?<!:) # no colon before - prevents matching roles
"""
+ LINK_CORE,
re.VERBOSE, # whitespace and comments are ignored
)


def redown(text: str) -> str:
"""21"""

Expand Down Expand Up @@ -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"(?<!:)\[([^\]\n]+?)\]\(([^)]+?)\)",
r"`\1 <\2>`__",
links = lambda: LINK_RE.sub(
lambda m: f"`{(t:=m.group('text'))}{' ' if len(t) else ''}<{m.group('link')}>`__",
text,
)
text = links()
Expand Down
1 change: 0 additions & 1 deletion source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.*",
]

Expand Down

0 comments on commit 8d3c821

Please sign in to comment.