mkdocstrings / autorefs

Automatically link across pages in MkDocs.
https://mkdocstrings.github.io/autorefs/
ISC License
51 stars 7 forks source link

Register heading title to add it back as `title` attribute #33

Open pawamoy opened 1 year ago

pawamoy commented 1 year ago

@waylan noticed that links created by autorefs with the [title][id] syntax do not have a title HTML attribute. It would be nice to have a title in any case:

As to how to record these:

An alternative would be to reuse the provided identifier in [title][id] as title HTML attribute if it is different than the provided title, but that would only make sense for objects, not regular headings (we don't want to show a tooltip on hover with a heading's slug).

Boost priority

Fund with Polar

waylan commented 1 year ago

I was curious how this plugin worked and see that your reference store is of the format dict[str, str]. However, Python Markdown's store is of the format dict[str, tuple[str, str]] as you can see in markdown/blockprocessors.py#L574 (self.parser.md.references[id] = (link, title)). Presumably, if you did the same, you would know what the source of the reference was when creating it and could more easily determine a title at that time. For example, you would know you were creating a reference for a code object and could generate a title when saving to the store. For that matter, you could even store the label of TOC links as titles.