Skip to content

Commit

Permalink
chore: Add YORE comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Sep 1, 2024
1 parent 2916eb2 commit e422990
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/mkdocs_autorefs/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
log = logging.getLogger(f"mkdocs.plugins.{__name__}") # type: ignore[assignment]


# YORE: Bump 2: Remove block.
def __getattr__(name: str) -> Any:
if name == "AutoRefInlineProcessor":
warnings.warn("AutoRefInlineProcessor was renamed AutorefsInlineProcessor", DeprecationWarning, stacklevel=2)
Expand All @@ -41,6 +42,8 @@ def __getattr__(name: str) -> Any:


_ATTR_VALUE = r'"[^"<>]+"|[^"<> ]+' # Possibly with double quotes around

# YORE: Bump 2: Remove block.
AUTO_REF_RE = re.compile(
rf"<span data-(?P<kind>autorefs-(?:identifier|optional|optional-hover))=(?P<identifier>{_ATTR_VALUE})"
rf"(?: class=(?P<class>{_ATTR_VALUE}))?(?P<attrs> [^<>]+)?>(?P<title>.*?)</span>",
Expand Down Expand Up @@ -174,6 +177,7 @@ def relative_url(url_a: str, url_b: str) -> str:
return f"{relative}#{anchor}"


# YORE: Bump 2: Remove block.
def _legacy_fix_ref(url_mapper: Callable[[str], str], unmapped: list[str]) -> Callable:
"""Return a `repl` function for [`re.sub`](https://docs.python.org/3/library/re.html#re.sub).
Expand Down Expand Up @@ -300,6 +304,7 @@ def inner(match: Match) -> str:
return inner


# YORE: Bump 2: Replace `, *, _legacy_refs: bool = True` with `` within line.
def fix_refs(html: str, url_mapper: Callable[[str], str], *, _legacy_refs: bool = True) -> tuple[str, list[str]]:
"""Fix all references in the given HTML text.
Expand All @@ -313,8 +318,11 @@ def fix_refs(html: str, url_mapper: Callable[[str], str], *, _legacy_refs: bool
"""
unmapped: list[str] = []
html = AUTOREF_RE.sub(fix_ref(url_mapper, unmapped), html)

# YORE: Bump 2: Remove block.
if _legacy_refs:
html = AUTO_REF_RE.sub(_legacy_fix_ref(url_mapper, unmapped), html)

return html, unmapped


Expand Down

0 comments on commit e422990

Please sign in to comment.