markdown icon indicating copy to clipboard operation
markdown copied to clipboard

Support direct navigation to individual items in def_list

Open jasper-zanjani opened this issue 4 years ago • 5 comments

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.

jasper-zanjani avatar Mar 26 '21 14:03 jasper-zanjani

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.

waylan avatar Mar 26 '21 14:03 waylan

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>

waylan avatar Mar 26 '21 14:03 waylan

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.

jasper-zanjani avatar Mar 26 '21 15:03 jasper-zanjani

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 avatar Mar 16 '23 10:03 ssbarnea

@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.

waylan avatar Mar 16 '23 13:03 waylan