markdown
markdown copied to clipboard
Support direct navigation to individual items in def_list
In a knowledge base with many terms, using the Definition list extension as-is requires use of text search or simply scrolling. This is because there is no way to easily navigate to a specific Definition List item. If an id attribute were generated as it is for headings, users would be able to create links to the specific item in the body of the page.
I have posted a similar request as #2495 in the squidfunk/mkdocs-material repo.
Have you tried using the attr_list extension, which allows you to define your own IDs on elements?
That said, autogenerated IDs would be a reasonable feature of the def_list extension, perhaps as an optional feature which is enabled by a config option. A PR adding such a feature would certainly be considered.
Here is an example using the attr_list extension:
foo { #foo }
: bar
key { #key }
: value
which generates the following HTML:
<dl>
<dt id="foo">foo</dt>
<dd>bar</dd>
<dt id="key">key</dt>
<dd>value</dd>
</dl>
True, that is an acceptable workaround. If def_list supported a configuration option to automatically create those, it would save a lot of fat-fingering.
I do not think that this fully works correctly because I do not see the link acting when I hover of the the definitions lists.
I checked and the anchors are created, so you could use them for referencing but users cannot copy a bookmark due to lack of hover option (like we have on headings).
This impacts the UX, as nobody will know how to share a link to a specific definition list entry.
Looking at the source of headers, I see
<h2 id="general-parameters">General parameters<a class="headerlink" href="#general-parameters" title="Permanent link">¶</a></h2>
While the DL entries have the expected id, they lack the magic bit to be made fully usable.
Did anyone managed to implement a full solution for this?
@ssbarnea this issue is tagged as 'someday-maybe' which suggests that it is a low priority item which is not going to get any attention by the core developers. If someone would like a full solution, then they will need to do the work and submit a PR, which we will be happy to review.