Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[[toc]] only generate same link when two or more headers are same #2030

Open
1 task done
puiiyuen opened this issue Nov 19, 2019 · 8 comments · May be fixed by #2210
Open
1 task done

[[toc]] only generate same link when two or more headers are same #2030

puiiyuen opened this issue Nov 19, 2019 · 8 comments · May be fixed by #2210
Labels
contribution welcome Contributions welcome type: bug Something isn't working

Comments

@puiiyuen
Copy link

puiiyuen commented Nov 19, 2019

  • I confirm that this is an issue rather than a question.

Bug report

When there are two or more headers in same name, the [[toc]] only generates one link for all same name headers. Other headers cannot be navigated to the right positions. Btw, the sidebar works well!

Steps to reproduce

# Test toc

[[toc]]

## Header 1
<!-- same header name -->
### Header 2
- Under *first* header 2 
- Under *first* header 2 

### Header 3
- Under header 3

## Header 4
<!-- same header name -->
### Header 2
- Under *second* header 2 
- Under *second* header 2 

What is expected?

They should be different links:
First "Header 2": localhost:8000/docs/test/test.html#header-2
Second "Header 2": localhost:8000/docs/test/test.html#header-2-2

What is actually happening?

They are same:
First "Header 2": localhost:8000/docs/test/test.html#header-2
Second "Header 2": localhost:8000/docs/test/test.html#header-2

Other relevant information

  • Output of npx vuepress info in my VuePress project:
    Environment Info:
  System:
    OS: macOS 10.15.1
    CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
  Binaries:
    Node: 13.1.0 - /usr/local/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.13.1 - /usr/local/bin/npm
  Browsers:
    Chrome: 78.0.3904.70
    Firefox: Not Found
    Safari: 13.0.3
  npmPackages:
    @vuepress/core: Not Found
    @vuepress/theme-default: Not Found
    vuepress: Not Found
  npmGlobalPackages:
    vuepress: 1.2.0

@meteorlxy
Copy link
Member

meteorlxy commented Nov 21, 2019

That could be an issue of markdown-it-table-of-contents.

You can try vuepress-plugin-table-of-contents

@puiiyuen
Copy link
Author

Thanks, man!

It seems that markdown-it-table-of-contents has not been maintained for a long time.

vuepress-plugin-table-of-contents works well. Hopefully, vuepress will replace it as default toc compoent.

@meteorlxy
Copy link
Member

We used to replace it, but reverted in a previous version due to some reasons.

Maybe it could be the default toc component in a future version

@kefranabg kefranabg added type: bug Something isn't working contribution welcome Contributions welcome labels Nov 22, 2019
@kefranabg
Copy link
Collaborator

I agree, let's check if vuepress-plugin-table-of-contents can do the job!

@haoranpb
Copy link
Contributor

haoranpb commented Feb 25, 2020

I made a demo with vuepress-plugin-table-of-contents.

I think it also works well in #1985 's situation, though it will not display the badge.

Any idea why it's reverted in the first place?

Also, it's a breaking change

current
[[toc]]

vuepress-plugin-table-of-contents
<TOC />

@meteorlxy
Copy link
Member

meteorlxy commented Feb 25, 2020

I remembered that it was not a complex issue. @ludanxer if you are interested, I could help to find the history:

@meteorlxy
Copy link
Member

meteorlxy commented Feb 25, 2020

#1375 Tried to replace the [[toc]] syntax to avoid introducing breaking changes, which caused a ssr-mismatch issue.

As I remembered, the [[toc]] syntax will generate HTML like <p><div></div></p>, which is invalid.

@haoranpb
Copy link
Contributor

haoranpb commented Mar 1, 2020

Found two other related history #1436 , #1596

@haoranpb haoranpb linked a pull request Mar 2, 2020 that will close this issue
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution welcome Contributions welcome type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants