thlorenz / doctoc

📜 Generates table of contents for markdown files inside local git repository. Links are compatible with anchors generated by github or other sites.
https://www.npmjs.com/package/doctoc
MIT License
4.26k stars 480 forks source link

Some minor parsing issues for GitHub markdown #92

Open EdmundKorley opened 8 years ago

EdmundKorley commented 8 years ago

When parsing: a header named

this identifier

(Note the code formating) doctoc yields:

#this-identifier

... when it should yield:

#-this-identifier

This is because, -this-identifier, rather than this-identifier, is the actual id that GitHub renders when it converts the markdown to HTML for display. As a result the generated doctoc link will not work as a relative link.

There are a few other examples of this like:

For

Header & noise

doctoc produces

#header-&-noise

which will lead to a dead link in GitHub markdown rather than the appropriate

#header-noise

rm-hull commented 8 years ago

For the #header-&-noise case, I think the result should be a double dash: #header--noise

jez commented 8 years ago

The #thisidentifier example currently works correctly on GitHub.

The # Header & noise example is indeed a bug though.

The fix is almost identical to thlorenz/anchor-markdown-header#29.

richbodo commented 6 years ago

For the #header-&-noise case, the result should be a single dash: #header-noise.

Tested on github and gitlab - the link generated ignored the ampersand entirely, and uses a single hyphen.

karfau commented 6 years ago

I would guess that it converts all special chars to - and merges multiple sequenced - into a single one. But maybe it is possible to look at the code behind this to be sure?