Skip to content

Commit c980d18

Browse files
committed
Merge branch 'main' into backlinks
2 parents c58c1c5 + e35ce91 commit c980d18

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

Diff for: CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

77
<!-- insertion marker -->
8+
## [1.3.1](https://github.com/mkdocstrings/autorefs/releases/tag/1.3.1) - 2025-02-11
9+
10+
<small>[Compare with 1.3.0](https://github.com/mkdocstrings/autorefs/compare/1.3.0...1.3.1)</small>
11+
12+
### Bug Fixes
13+
14+
- Always resolve secondary URLs to closest (don't log warnings) ([243ad35](https://github.com/mkdocstrings/autorefs/commit/243ad35f193b48216b531333e0d91ab2fa0a0db4) by Timothée Mazzucotelli). [Issue-52](https://github.com/mkdocstrings/autorefs/issues/52)
15+
816
## [1.3.0](https://github.com/mkdocstrings/autorefs/releases/tag/1.3.0) - 2025-01-12
917

1018
<small>[Compare with 1.2.0](https://github.com/mkdocstrings/autorefs/compare/1.2.0...1.3.0)</small>

Diff for: src/mkdocs_autorefs/plugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def _get_item_url(
300300
raise
301301

302302
if len(urls) > 1:
303-
if self.config.resolve_closest and from_url is not None:
303+
if (self.config.resolve_closest or qualifier == "secondary") and from_url is not None:
304304
return self._get_closest_url(from_url, urls, qualifier)
305305
log.warning(
306306
"Multiple %s URLs found for '%s': %s. "

Diff for: tests/test_plugin.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -94,26 +94,30 @@ def test_register_secondary_url() -> None:
9494
assert plugin._secondary_url_map == {"foo": {"foo.html#foo": None}}
9595

9696

97-
def test_warn_multiple_urls(caplog: pytest.LogCaptureFixture) -> None:
97+
@pytest.mark.parametrize("primary", [True, False])
98+
def test_warn_multiple_urls(caplog: pytest.LogCaptureFixture, primary: bool) -> None:
9899
"""Warn when multiple URLs are found for the same identifier."""
99100
plugin = AutorefsPlugin()
100101
plugin.config = AutorefsConfig()
101-
plugin.register_anchor(identifier="foo", page="foo.html", primary=True)
102-
plugin.register_anchor(identifier="foo", page="bar.html", primary=True)
102+
plugin.register_anchor(identifier="foo", page="foo.html", primary=primary)
103+
plugin.register_anchor(identifier="foo", page="bar.html", primary=primary)
103104
url_mapper = functools.partial(plugin.get_item_url, from_url="/hello")
104105
# YORE: Bump 2: Replace `, _legacy_refs=False` with `` within line.
105106
fix_refs('<autoref identifier="foo">Foo</autoref>', url_mapper, _legacy_refs=False)
106-
assert "Multiple primary URLs found for 'foo': ['foo.html#foo', 'bar.html#foo']" in caplog.text
107+
qualifier = "primary" if primary else "secondary"
108+
assert (f"Multiple {qualifier} URLs found for 'foo': ['foo.html#foo', 'bar.html#foo']" in caplog.text) is primary
107109

108110

109-
def test_use_closest_url(caplog: pytest.LogCaptureFixture) -> None:
111+
@pytest.mark.parametrize("primary", [True, False])
112+
def test_use_closest_url(caplog: pytest.LogCaptureFixture, primary: bool) -> None:
110113
"""Use the closest URL when multiple URLs are found for the same identifier."""
111114
plugin = AutorefsPlugin()
112115
plugin.config = AutorefsConfig()
113116
plugin.config.resolve_closest = True
114-
plugin.register_anchor(identifier="foo", page="foo.html", primary=True)
115-
plugin.register_anchor(identifier="foo", page="bar.html", primary=True)
117+
plugin.register_anchor(identifier="foo", page="foo.html", primary=primary)
118+
plugin.register_anchor(identifier="foo", page="bar.html", primary=primary)
116119
url_mapper = functools.partial(plugin.get_item_url, from_url="/hello")
117120
# YORE: Bump 2: Replace `, _legacy_refs=False` with `` within line.
118121
fix_refs('<autoref identifier="foo">Foo</autoref>', url_mapper, _legacy_refs=False)
119-
assert "Multiple primary URLs found for 'foo': ['foo.html#foo', 'bar.html#foo']" not in caplog.text
122+
qualifier = "primary" if primary else "secondary"
123+
assert f"Multiple {qualifier} URLs found for 'foo': ['foo.html#foo', 'bar.html#foo']" not in caplog.text

0 commit comments

Comments
 (0)