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

Headers with special characters between words should be converted to "-" #67

Closed LeonnardoVerol closed 4 years ago

LeonnardoVerol commented 4 years ago

Bug report

When creating headers with special characters between words, is it expected that the special character will be changed to "-"

Steps to reproduce

Create duplicated Headers (same name) inside a markdown file

# header & header

What is expected?

The anchor link for the header should be:

#header--header

What is actually happening?

It is generating the following anchor links:

#header-header
nagaozen commented 4 years ago

This library is "slugification" agnostic. id est we don't decide what is the right or wrong way to make your links prettier. The default behavior is to just take the header content and encodeURIComponent it. That said, in the early days we leveraged the slugify library and it's expected output for your input is header-and-header, but we don't expect it as a dependency anymore.

Developers are free to decide what strategy is better for'em because they know more their application use cases than us. So, just pass a slugify function that tastes good for you.

Have a nice day.