vuepress / vuepress-community

:bulb: Community supported ecosystem for VuePress
https://vuepress-community.netlify.app
MIT License
81 stars 62 forks source link

fix(plugin-smooth-scroll): get target element by id or name #58

Closed microJ closed 4 years ago

microJ commented 4 years ago

Summary

Which package does this PR involve? (check one)

What kind of change does this PR introduce? (check at least one)

Does this PR introduce a breaking change? (check one)

If yes, please describe the impact and migration path for existing applications:

The PR fulfills these requirements:

Other information:

问题描述: 复现链接,https://blog.expect2.cyou/views/front-end/2020/0824-speed-up-npm-install.html#5f447c564bdcde0006a8ffd6 ,打开控制台可以看到报错。 某些自动生成的hash以数字开头,直接使用 #123 作为 selectors 会报错。

修改内容:

  1. 获取数字开头的 hash 时不报错
  2. 兼容设置 name="targetAnchor" 的锚点
meteorlxy commented 4 years ago

兼容设置 name="targetAnchor" 的锚点

html5 中锚点不应再设置 name 了吧

microJ commented 4 years ago

html5 中锚点不应再设置 name 了吧

@meteorlxy

经查 w3c 标明了 name 属性是废弃的:The name attribute on the a element is obsolete. Consider putting an id attribute on the nearest container instead. 但是查证 whatwg,表示 hash-name reference that has an id or name attribute,fragment 对应元素查找过程解释在这里:https://html.spec.whatwg.org/#find-a-potential-indicated-element

这里应该是以 whatwg 为准的吧 =。=

meteorlxy commented 4 years ago

Thanks! ❤️