Skip to content

Commit

Permalink
refactor: Support fallback method returning multiple identifiers
Browse files Browse the repository at this point in the history
Issue #11: #11
  • Loading branch information
pawamoy committed Nov 28, 2021
1 parent 76fc551 commit d6e1178
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/mkdocs_autorefs/plugin.py
Expand Up @@ -10,6 +10,7 @@
and fixes them using the previously stored identifier-URL mapping.
"""

import contextlib
import functools
import logging
from typing import Callable, Dict, Optional
Expand Down Expand Up @@ -90,10 +91,12 @@ def get_item_url(
return self._abs_url_map[identifier]

if fallback:
new_identifier = fallback(identifier)
if new_identifier:
return self.get_item_url(new_identifier, from_url)

new_identifiers = fallback(identifier)
for new_identifier in new_identifiers:
with contextlib.suppress(KeyError):
url = self.get_item_url(new_identifier, from_url)
self._url_map[identifier] = url # update the map to avoid doing all this again
return url
raise

if from_url is not None:
Expand Down

0 comments on commit d6e1178

Please sign in to comment.