Skip to content

Commit 8a4de0c

Browse files
committed
fixup! refactor: Add backlinks metadata to autorefs elements
1 parent 0fd25e6 commit 8a4de0c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/mkdocstrings_handlers/python/handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from collections.abc import Iterator, Mapping, MutableMapping, Sequence
3535

3636
from mkdocs.config.defaults import MkDocsConfig
37+
from mkdocs_autorefs.plugin import Backlink
3738

3839

3940
if sys.version_info >= (3, 11):
@@ -274,7 +275,7 @@ def render(self, data: CollectorItem, options: PythonOptions) -> str: # noqa: D
274275
},
275276
)
276277

277-
def render_backlinks(self, backlinks: Mapping[str, Iterable[str]]) -> str: # noqa: D102 (ignore missing docstring)
278+
def render_backlinks(self, backlinks: Mapping[str, Iterable[Backlink]]) -> str: # noqa: D102 (ignore missing docstring)
278279
template = self.env.get_template("backlinks.html.jinja")
279280
verbose_type = {key: key.capitalize().replace("-by", " by") for key in backlinks.keys()}
280281
return template.render(backlinks=backlinks, config=self.get_options({}), verbose_type=verbose_type)

src/mkdocstrings_handlers/python/templates/material/_base/backlinks.html.jinja

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,21 @@ Context:
1919
{% for backlink_type, backlink_list in backlinks | dictsort %}
2020
<b class="doc doc-backlink-type">{{ verbose_type[backlink_type] }}:</b>
2121
<ul class="doc doc-backlink-list">
22-
{% for url, title in backlink_list | sort(attribute=1) %}
23-
<li><a href="{{ url }}" class="doc doc-backlink">{{ (title or url.split("#", 1)[-1]) | safe }}</a></li>
22+
{% for backlink in backlink_list | sort(attribute="crumbs") %}
23+
<li class="doc doc-backlink">
24+
{% for crumb in backlink.crumbs | reverse %}
25+
{% if crumb.url %}
26+
<a class="doc doc-backlink-crumb" href="{{ crumb.url }}">{{ crumb.title | safe }}</a>
27+
{% else %}
28+
<span class="doc doc-backlink-crumb">{{ crumb.title | safe }}</span>
29+
{% endif %}
30+
{% if not loop.last %}
31+
<span class="twemoji">
32+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M8.59 16.58 13.17 12 8.59 7.41 10 6l6 6-6 6z"/></svg>
33+
</span>
34+
{% endif %}
35+
{% endfor %}
36+
</li>
2437
{% endfor %}
2538
</ul>
2639
{% endfor %}

0 commit comments

Comments
 (0)