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

Use header's slug as it is if possible #119

Merged
merged 1 commit into from
Apr 18, 2018
Merged

Use header's slug as it is if possible #119

merged 1 commit into from
Apr 18, 2018

Conversation

hatashiro
Copy link
Contributor

This fixes an issue concerning missing slug link of sidebar.

Reproduction

The issue can even be reproduced in the official VuePress guide.

  1. Access https://vuepress.vuejs.org/guide/
  2. Click the Why Not ...? link in sidebar

We can see that the guide page doesn't scroll to the Why Not ...? header.

Reason

The issue is caused by markdown-it's typographer: true option, which is for beautification. By the option, three dots (...) are replaced with a single unicode character . They are handled differently by slugify().

When logging the tokens, tokens[i + 1].content is not typographer-ed, even its actual slug is.

Fix

The token already has an attribute id which is a correct and final result of the parser. Also, the slug is used for sidebar links later, so I guess it would be more proper to use id as it is.

Please let me know if there is anything unclear.

Thanks!

@hg-pyun
Copy link

hg-pyun commented Apr 18, 2018

LGTM

@@ -59,10 +59,11 @@ exports.extractHeaders = (content, include = [], md) => {
tokens.forEach((t, i) => {
if (t.type === 'heading_open' && include.includes(t.tag)) {
const title = tokens[i + 1].content
const slug = t.attrs.find(([name]) => name === 'id')[1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using Array.prototype.find since Buble doesn't polyfill for it and it won't work at IE11.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lib/util only runs in Node so it's ok

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, excuse me, I forget some important thing.

Copy link
Member

@ulivz ulivz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Run this at local and looks good to me, not check details

@yyx990803 yyx990803 merged commit 5f7e199 into vuejs:master Apr 18, 2018
@hatashiro
Copy link
Contributor Author

Thanks!

meteorlxy added a commit that referenced this pull request Jun 17, 2021
Co-authored-by: meteorlxy <meteor.lxy@foxmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants