|
22 | 22 | patch_loggers, |
23 | 23 | ) |
24 | 24 | from mkdocs.exceptions import PluginError |
| 25 | +from mkdocs_autorefs import BacklinkCrumb |
25 | 26 | from mkdocstrings import BaseHandler, CollectionError, CollectorItem, HandlerOptions, Inventory, get_logger |
26 | 27 |
|
27 | 28 | from mkdocstrings_handlers.python._internal import rendering |
28 | 29 | from mkdocstrings_handlers.python._internal.config import PythonConfig, PythonOptions |
29 | 30 |
|
30 | 31 | if TYPE_CHECKING: |
31 | | - from collections.abc import Iterator, Mapping, MutableMapping, Sequence |
| 32 | + from collections.abc import Iterable, Iterator, Mapping, MutableMapping, Sequence |
32 | 33 |
|
33 | 34 | from mkdocs.config.defaults import MkDocsConfig |
| 35 | + from mkdocs_autorefs import Backlink |
34 | 36 |
|
35 | 37 |
|
36 | 38 | # YORE: EOL 3.10: Replace block with line 2. |
@@ -306,6 +308,24 @@ def render(self, data: CollectorItem, options: PythonOptions, locale: str | None |
306 | 308 | }, |
307 | 309 | ) |
308 | 310 |
|
| 311 | + def render_backlinks(self, backlinks: Mapping[str, Iterable[Backlink]], *, locale: str | None = None) -> str: # noqa: ARG002 |
| 312 | + """Render the backlinks. |
| 313 | +
|
| 314 | + Parameters: |
| 315 | + backlinks: The backlinks to render. |
| 316 | +
|
| 317 | + Returns: |
| 318 | + The rendered backlinks (HTML). |
| 319 | + """ |
| 320 | + template = self.env.get_template("backlinks.html.jinja") |
| 321 | + verbose_type = {key: key.capitalize().replace("-by", " by") for key in backlinks.keys()} # noqa: SIM118 |
| 322 | + return template.render( |
| 323 | + backlinks=backlinks, |
| 324 | + config=self.get_options({}), |
| 325 | + verbose_type=verbose_type, |
| 326 | + default_crumb=BacklinkCrumb(title="", url=""), |
| 327 | + ) |
| 328 | + |
309 | 329 | def update_env(self, config: Any) -> None: # noqa: ARG002 |
310 | 330 | """Update the Jinja environment with custom filters and tests. |
311 | 331 |
|
|
0 commit comments