Skip to content

Commit d6e1178

Browse files
committed
refactor: Support fallback method returning multiple identifiers
Issue #11: #11
1 parent 76fc551 commit d6e1178

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/mkdocs_autorefs/plugin.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
and fixes them using the previously stored identifier-URL mapping.
1111
"""
1212

13+
import contextlib
1314
import functools
1415
import logging
1516
from typing import Callable, Dict, Optional
@@ -90,10 +91,12 @@ def get_item_url(
9091
return self._abs_url_map[identifier]
9192

9293
if fallback:
93-
new_identifier = fallback(identifier)
94-
if new_identifier:
95-
return self.get_item_url(new_identifier, from_url)
96-
94+
new_identifiers = fallback(identifier)
95+
for new_identifier in new_identifiers:
96+
with contextlib.suppress(KeyError):
97+
url = self.get_item_url(new_identifier, from_url)
98+
self._url_map[identifier] = url # update the map to avoid doing all this again
99+
return url
97100
raise
98101

99102
if from_url is not None:

0 commit comments

Comments
 (0)