Skip to content

Commit

Permalink
chore: Add Yore comments above legacy ref stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
pawamoy committed Jan 10, 2025
1 parent 5e89cd8 commit 861beeb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/mkdocs_autorefs/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class AutorefsPlugin(BasePlugin[AutorefsConfig]):

scan_toc: bool = True
current_page: str | None = None
# YORE: Bump 2: Remove line.
legacy_refs: bool = True

def __init__(self) -> None:
Expand Down Expand Up @@ -349,6 +350,7 @@ def on_post_page(self, output: str, page: Page, **kwargs: Any) -> str: # noqa:

# YORE: Bump 2: Replace `, fallback=self.get_fallback_anchor` with `` within line.
url_mapper = functools.partial(self.get_item_url, from_url=page.url, fallback=self.get_fallback_anchor)
# YORE: Bump 2: Replace `, _legacy_refs=self.legacy_refs` with `` within line.
fixed_output, unmapped = fix_refs(output, url_mapper, _legacy_refs=self.legacy_refs)

if unmapped and log.isEnabledFor(logging.WARNING):
Expand Down
5 changes: 2 additions & 3 deletions src/mkdocs_autorefs/references.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,11 @@ 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,
# YORE: Bump 2: Remove line.
_legacy_refs: bool = True, # noqa: FBT001, FBT002
) -> tuple[str, list[tuple[str, AutorefsHookInterface.Context | None]]]:
"""Fix all references in the given HTML text.
Expand Down
2 changes: 2 additions & 0 deletions tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_warn_multiple_urls(caplog: pytest.LogCaptureFixture) -> None:
plugin.register_anchor(identifier="foo", page="foo.html", primary=True)
plugin.register_anchor(identifier="foo", page="bar.html", primary=True)
url_mapper = functools.partial(plugin.get_item_url, from_url="/hello")
# YORE: Bump 2: Replace `, _legacy_refs=False` with `` within line.
fix_refs('<autoref identifier="foo">Foo</autoref>', url_mapper, _legacy_refs=False)
assert "Multiple primary URLs found for 'foo': ['foo.html#foo', 'bar.html#foo']" in caplog.text

Expand All @@ -113,5 +114,6 @@ def test_use_closest_url(caplog: pytest.LogCaptureFixture) -> None:
plugin.register_anchor(identifier="foo", page="foo.html", primary=True)
plugin.register_anchor(identifier="foo", page="bar.html", primary=True)
url_mapper = functools.partial(plugin.get_item_url, from_url="/hello")
# YORE: Bump 2: Replace `, _legacy_refs=False` with `` within line.
fix_refs('<autoref identifier="foo">Foo</autoref>', url_mapper, _legacy_refs=False)
assert "Multiple primary URLs found for 'foo': ['foo.html#foo', 'bar.html#foo']" not in caplog.text
5 changes: 5 additions & 0 deletions tests/test_references.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def test_reference_with_markup() -> None:
)


# YORE: Bump 2: Remove block.
def test_legacy_custom_required_reference() -> None:
"""Check that external HTML-based references are expanded or reported missing."""
with pytest.warns(DeprecationWarning, match="`span` elements are deprecated"):
Expand All @@ -241,6 +242,7 @@ def test_custom_required_reference() -> None:
)


# YORE: Bump 2: Remove block.
def test_legacy_custom_optional_reference() -> None:
"""Check that optional HTML-based references are expanded and never reported missing."""
with pytest.warns(DeprecationWarning, match="`span` elements are deprecated"):
Expand All @@ -260,6 +262,7 @@ def test_custom_optional_reference() -> None:
)


# YORE: Bump 2: Remove block.
def test_legacy_custom_optional_hover_reference() -> None:
"""Check that optional-hover HTML-based references are expanded and never reported missing."""
with pytest.warns(DeprecationWarning, match="`span` elements are deprecated"):
Expand All @@ -279,6 +282,7 @@ def test_custom_optional_hover_reference() -> None:
)


# YORE: Bump 2: Remove block.
def test_legacy_external_references() -> None:
"""Check that external references are marked as such."""
with pytest.warns(DeprecationWarning, match="`span` elements are deprecated"):
Expand Down Expand Up @@ -386,6 +390,7 @@ def test_register_markdown_anchors_with_admonition() -> None:
}


# YORE: Bump 2: Remove block.
def test_legacy_keep_data_attributes() -> None:
"""Keep HTML data attributes from autorefs spans."""
with pytest.warns(DeprecationWarning, match="`span` elements are deprecated"):
Expand Down

0 comments on commit 861beeb

Please sign in to comment.