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

Headings containing a hashtag yield invalid hrefs #103

Closed AleksandrHovhannisyan closed 3 years ago

AleksandrHovhannisyan commented 3 years ago

One thing I noticed today is that one of my pages is giving me HTML validation errors because it has a heading of the form:

# Approach #1: Do something

And that nested hashtag yields this invalid anchor URL:

#approach-#1-do-something

Would it be possible to remove this special character from the output href since it's not allowed to appear more than once?

valeriangalliat commented 3 years ago

Hey! We use encodeURIComponent as the defaut slugify function so out of the box your example should output:

<h1 id="approach-%231%3A-do-something" tabindex="-1">Approach #1: Do something</h1>

Did you customize the slugify function? Also what HTML validator are you using?

AleksandrHovhannisyan commented 3 years ago

Ah, that explains it! Yes, I customized it, and my custom slugify function wasn't handling that character. Thanks for the super quick response!