-
Notifications
You must be signed in to change notification settings - Fork 20
Fix anchor link positions in Chrome #708
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
base: main
Are you sure you want to change the base?
Conversation
| @@ -1,5 +1,5 @@ | |||
| // https://vitepress.dev/guide/custom-theme | |||
| import { h } from "vue"; | |||
| import { h, nextTick, watch } from "vue"; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the imports can be reverted back
| h1, h2, h3, h4, h5{ | ||
| /** For proper anchor offset when using scroll to hash links */ | ||
| scroll-margin-top: 60px; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
scroll-margin-top is not yet respected by vitepress' router. If you want this it needs to be configured in .vitepress/config, but the defaults already calculate the offset depending on the height on navbar, etc.. Probably can be removed.
| if (style.length > 0) { | ||
| const sep = existingStyle && !existingStyle.trim().endsWith(';') ? ';' : '' | ||
| token.attrSet('style', existingStyle + sep + style.join(' ')) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version works, but probably can be synced with the edits on the vitepress issue. I had made it simpler (just using string for styles as there is only one concat needed).
Fixes #656
Solution
After some discussion with @brc-dd in vitepress issues (see: vuejs/vitepress#5079), following improvements were implemented: