valeriangalliat / markdown-it-anchor

A markdown-it plugin that adds an `id` attribute to headings and optionally permalinks.
The Unlicense
291 stars 72 forks source link

Curly braces anchor definitions #87

Closed holtwick closed 3 years ago

holtwick commented 3 years ago

In my headings I define the anchor name like this:

# Header {#anchor-header}

Becomes something like:

<a href="#anchor-header"></a>
<h1 id="anchor-header">Header</h1>

This is a common pattern in multiple Markdown flavors.

The benefit for me is, that I can use the same anchors for various translations of my help texts.

Any chance to support this? Thanks.

valeriangalliat commented 3 years ago

You should be able to use markdown-it-attrs for this (make sure to load it before markdown-it-anchor)!

markdown-it-anchor is designed to reuse an existing id attribute if there's any, so it will only add an id to the titles that don't have one yet.

Let me know if that helps!

holtwick commented 3 years ago

This is exactly what I was looking for! Thanks a lot, you made my day. It is even better than my previous solution ;)

You should consider adding this hint to the README.