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

The anchor doesn't work if there's an “й” in it. #4605

Open
4 tasks done
Alexufo opened this issue Mar 7, 2025 · 4 comments
Open
4 tasks done

The anchor doesn't work if there's an “й” in it. #4605

Alexufo opened this issue Mar 7, 2025 · 4 comments
Labels
has-workaround Has workaround, low priority needs more discussion

Comments

@Alexufo
Copy link

Alexufo commented Mar 7, 2025

Describe the bug

The anchor doesn't work if there's an “й” in it.

Reproduction

Please test. "Движок авто" works fine, but "Настройки сессии" will not scroll down

[Движок авто](#движок-авто)
[Настройки сессии](#настройки-сессии)
<br>
<br>
<br>
<br> 300 times...

## Настройки сессии
## Движок авто

Expected behavior

works as other words

System Info

viteress 1.6.3

Additional context

No response

Validations

@Alexufo Alexufo added the bug: pending triage Maybe a bug, waiting for confirmation label Mar 7, 2025
@brc-dd
Copy link
Member

brc-dd commented Mar 7, 2025

Hmm, the anchor for heading is being normalized but the link isn't. Bit tricky to solve. A workaround is to specify normalized version - [Настройки сессии](#настроики-сессии) but it might appear as a typo and won't work properly with markdownlint/vscode. Another option is to adjust the slugify function so it behaves similar to your IDE:

// .vitepress/config.ts

import { defineConfig } from 'vitepress'

export default defineConfig({
  markdown: {
    anchor: {
      slugify: (s) => s.replace(/\s+/g, '-').toLowerCase()
    }
  }
})

markdownlint uses this function which used to be the one that github used 👀

      slugify: (s) =>
        s
          .toLowerCase()
          .replace(/[^\p{Letter}\p{Mark}\p{Number}\p{Connector_Punctuation}\- ]/gu, '')
          .replace(/ /gu, '-')

vscode uses this:

https://github.com/microsoft/vscode/blob/2b3cb533550639a43a144968b07576998a880718/extensions/markdown-language-features/notebook/index.ts#L406-L412

@brc-dd brc-dd added needs more discussion and removed bug: pending triage Maybe a bug, waiting for confirmation labels Mar 7, 2025
@userquin
Copy link
Member

userquin commented Mar 7, 2025

@brc-dd I use loadash-es/deburr to normalize search strings, your script is not working, run this in your devtools console (Chrome):

const data1 = 'движок-авто'
const data2 = 'настройки-сессии'
const deburr = await import('https://cdn.jsdelivr.net/npm/[email protected]/+esm').then(m => m.default?.deburr || m.deburr)
console.log(deburr(data1.normalize('NFD'))))
// движок-авто
console.log(deburr(data2.normalize('NFD')))
// настроики-сессии

@userquin
Copy link
Member

userquin commented Mar 7, 2025

On firefox you can go to here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/normalize, and replace Try it code with this one and run it:

const data1 = 'движок-авто'
const data2 = 'настройки-сессии'
import('https://cdn.jsdelivr.net/npm/[email protected]/+esm').then(m => m.default?.deburr || m.deburr).then((deburr) => {
  console.log(deburr(data1.normalize('NFD')))
  // движок-авто
  console.log(deburr(data2.normalize('NFD')))
  // настроики-сессии
})

@brc-dd
Copy link
Member

brc-dd commented Mar 7, 2025

No actually we need настройки-сессии there, to align with vscode's intellisense or github's preview.

This is what github generates: (which is similar to markdownlint's function)

Image


VitePress currently generates настроики-сессии (same as what you wrote) using https://github.com/mdit-vue/mdit-vue/blob/main/packages/shared/src/slugify.ts. But it doesn't normalize the url fragments in links.

@brc-dd brc-dd added the has-workaround Has workaround, low priority label Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has-workaround Has workaround, low priority needs more discussion
Projects
None yet
Development

No branches or pull requests

3 participants