Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable markdown attributes for dt elements #11566

Open
jmooring opened this issue Oct 15, 2023 · 5 comments
Open

Enable markdown attributes for dt elements #11566

jmooring opened this issue Oct 15, 2023 · 5 comments
Labels
Milestone

Comments

@jmooring
Copy link
Member

jmooring commented Oct 15, 2023

This markdown:

term
: definition

is currently rendered to:

<dl>
  <dt>term</dt>
  <dd>definition</dd>
</dl>

but what I really, really want is:

<dl>
  <dt id="term">term</dt>
  <dd>definition</dd>
</dl>

This would allow us to manually link to the term, which would be very useful on documentation sites, our documentation site in particular.

ID's should be assigned using the same logic as heading id's... use GitHub id format, and increment as needed to prevent duplicates on the same page (that means checking heading id's as well).

Other thoughts:

  • Should this have an on/off switch? I can't think of a reason to disable the functionality.
  • If we do this, at some point someone will want to override the id using a markdown attribute, like you can with headings. But we can't currently assign a markdown attribute to a list item, only to the list itself.
  • This could also be handled (sort of) with a markdown render hook (layouts/_default/_markup/render-dt.html), but you wouldn't have the ability to guarantee unique ids (the render hook would have no knowledge of other id's on the page).
  • At some point these could be added to the .Fragments map as well (perhaps useful for .Related).
  • You can use this link render hook hack, but the markdown isn't portable.

Reference: https://discourse.gohugo.io/t/automatically-add-id-attribute-to-dt-element/38191

@dvdksn
Copy link
Contributor

dvdksn commented Oct 16, 2023

instinctively I'd expect this to be configurable via markup.goldmark.parser, like heading IDs are. And that the strategy for generating these IDs are controlled the same way.

@bep bep removed the NeedsTriage label Oct 17, 2023
@bep bep added this to the v0.120.0 milestone Oct 17, 2023
@bep
Copy link
Member

bep commented Oct 17, 2023

Is is possible to do:

term
: definition
{#term}

?

Not saying that it's great, but then again, having stable IDs have its benefits.

@dvdksn
Copy link
Contributor

dvdksn commented Oct 17, 2023

@bep that would add the ID to the <dl> element

@Winterhuman
Copy link

Winterhuman commented Oct 21, 2023

I'd also want some form of toggle for the ID behaviour, purely for the sake of not needing them, but also because the content of <dt> elements isn't necessarily always short enough to be appropriately put into an ID value (since it can be used generically as a key-value store per its semantics).

(A render hook would be appreciated)

@bep bep modified the milestones: v0.120.0, v0.121.0 Oct 31, 2023
@bep bep modified the milestones: v0.121.0, v0.122.0 Dec 6, 2023
@jmooring
Copy link
Member Author

jmooring commented Dec 30, 2023

Thinking about this more, adding the ability to set markdown attributes on dt elements is probably the best way to handle this. For example:

Term A {#foo}
: Description of Term A
Term B {#bar}
: Description of Term B

Notes:

  • Automatically adding an id attribute to every dt element might be something to consider in the future.
  • On the doc site we (I) are currently hijacking h6 elements to make them look like dt elements.

@jmooring jmooring changed the title Automatically add id attribute to dt elements Enable markdown attributes for dt elements Dec 30, 2023
@bep bep modified the milestones: v0.122.0, v0.123.0, v0.124.0 Jan 27, 2024
@bep bep modified the milestones: v0.124.0, v0.125.0 Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants