vuejs / vuepress

📝 Minimalistic Vue-powered static site generator
https://vuepress.vuejs.org
MIT License
22.43k stars 4.79k forks source link

Some auto-generated TOC links do not match corresponding header anchors #2913

Open aspiers opened 2 years ago

aspiers commented 2 years ago

Bug report

Steps to reproduce

Generate a TOC with the markdown.slugify option set to use the default slugify from @vuepress/shared-utils. For example, see the .vuepress/config.js for hardhat.org.

What is expected?

Links from the TOC will correctly navigate to the corresponding auto-generated header anchors.

What is actually happening?

Some header links don't match the auto-generated header anchors.

Examples of inconsistencies:

Other relevant information

Please see https://hardhat.org/plugins/hardhat-deploy.html for a specific public example, and https://github.com/nomiclabs/hardhat/issues/1800 for the corresponding issue.

aspiers commented 2 years ago

I am confused where these inconsistencies are coming from, because I thought the same slugify function was supposed to handle anchor generation both for the TOC links and header anchors?

aspiers commented 2 years ago

Ah, I see there is a markdown.toc option, which says:

(Note: prefer markdown.slugify to customize header ids.)

but it looks the toc plugin is indeed using the same slugify:

https://github.com/vuejs/vuepress/blob/38e98634af117f83b6a32c8ff42488d91b66f663/packages/%40vuepress/markdown/index.js#L97-L102

which is defined here:

https://github.com/vuejs/vuepress/blob/38e98634af117f83b6a32c8ff42488d91b66f663/packages/%40vuepress/markdown/index.js#L45-L46

so I'm not sure what's going wrong. Perhaps parseHeaders is interfering somehow?