Skip to content

Markdown 链接中的锚点被 VitePress 修改了 #5051

@Tenormis

Description

@Tenormis

Describe the bug

Markdown 链接中以数字开头的锚点(我不确定是否还有其他情况也会有这个问题),编译后会被自动添加 _ 前缀。
In Markdown links, anchors (fragment identifiers) that start with a number (not sure if other cases are also affected) will automatically have an underscore _ prefixed after compilation.

Reproduction

markdown-examples.md:

## 1. Syntax Highlighting

### 1.1. HI 测试标题

[测试链接1](#11-hi-测试标题)

[测试链接2](api-examples.md#2-more)

[测试链接3](api-examples.md#final)

[测试链接4](api-examples.md#最后)

<a href="./api-examples#2-more">HTML 格式链接</a>

api-examples.md:

## 2. More

Check out the documentation for the [full list of runtime APIs](https://vitepress.dev/reference/runtime-api#usedata).

## Final

## 最后

编译后的 markdown-examples.html:
Generated markdown-examples.html:

<p><a href="#_11-hi-测试标题">测试链接1</a></p>
<p><a href="./api-examples#_2-more">测试链接2</a></p>
<p><a href="./api-examples#final">测试链接3</a></p>
<p><a href="./api-examples#最后">测试链接4</a></p>
<p><a href="./api-examples#2-more">HTML 格式链接</a></p>

“测试链接1” 和 “测试链接2” 的原始锚点被篡改了(添加了 _ 前缀)。
The original anchors for “Test Link 1” and “Test Link 2” were altered (an underscore _ was added).

“测试链接3”、“测试链接4”、“HTML 格式链接” 没有问题(保持原值不变)。
“Test Link 3”, “Test Link 4”, and the HTML-formatted link are unaffected (the original values remain unchanged).

Expected behavior

“测试链接1” 和 “测试链接2” 的锚点不应被篡改。
The anchors for “Test Link 1” and “Test Link 2” should not be modified.

System Info

略 (omitted)

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions