markd icon indicating copy to clipboard operation
markd copied to clipboard

Add toc link when enable set to true.

Open zw963 opened this issue 1 year ago • 7 comments

Enable display a link svg when set Markd::Options.new(toc: true), like following screenshot.

image

zw963 avatar Feb 11 '25 13:02 zw963

Anchor link is a part of toc, full toc feature needs to generate the table of content or provide a method to get the toc.

icyleaf avatar Mar 02 '25 04:03 icyleaf

generate the table of content

Yes, this is one of feature of toc, but i thought it's optional.

But, i consider anchor link is necessary for a HTML rendered markdown title.

zw963 avatar Mar 02 '25 16:03 zw963

I think this is something best implemented in a custom renderer rather than upstream

nobodywasishere avatar May 08 '25 16:05 nobodywasishere

I think this is something best implemented in a custom renderer rather than upstream

Yes, I use it on my fork, if we make the § string configurable, it is PR acceptable?

zw963 avatar May 09 '25 11:05 zw963

I'm not sure. On one hand this is useful; on the other this isn't something specified in the commonmark or gfm specs, which leads me towards it being something implemented by those who want it. How do we feel about out of spec extensions?

nobodywasishere avatar May 09 '25 16:05 nobodywasishere

I think anchor links for every heading are a very valuable UX feature.

However, it's a bit tricky getting the HTML right. The current implementation for example creates an anchor element adjacent to the header element. But they're not directly grouped together, which can make it hard to style properly. A commonly used structure wraps them into a div:

<div class="header-wrapper">
  <h2 id="title">Title</h2>
  <a href="#title">§</a>
</div>

Improving accessibility requires some further enhancements to make sense of the anchor link.

IMO a decent default implementation could very well fit into upstream. But it should also be easily customizable with custom renderers.

So maybe it's best to start with that to make sure it's simple to override the details without changing the overall structure?

straight-shoota avatar May 09 '25 16:05 straight-shoota

Maybe we can add a new option instead of toc for enable this PR feature, leave the toc only for original topic purpose.

zw963 avatar May 11 '25 13:05 zw963