facebook / facebook/docusaurus

onBrokenAnchors reports named anchor tags as broken links

オープン
#9,808 コメント 25 件 リアクション 3 件 担当者 0 名 GitHub で見る
bug
主要言語
TypeScript
スター
66.2k
フォーク
10k
平均マージ
1日 3時間
マージ済み PR(30日)
52

説明

### Have you read the Contributing Guidelines on issues?

- [X] I have read the [Contributing Guidelines on issues](https://github.com/facebook/docusaurus/blob/main/CONTRIBUTING.md#issues).

### Prerequisites

- [X] I'm using the latest version of Docusaurus.
- [X] I have tried the `npm run clear` or `yarn clear` command.
- [ ] I have tried `rm -rf node_modules yarn.lock package-lock.json` and re-installing packages.
- [ ] I have tried creating a repro with https://new.docusaurus.io.
- [ ] I have read the console error message carefully (if applicable).

### Description

When you use named anchors (E.g., `Some Text` or self-closing ) in a doc page, `onBrokenAnchors` reports it as a broken link.

### Reproducible demo

_No response_

### Steps to reproduce

1. In `docusaurus.config.js`, set `onBrokenAnchors` to `Warn` (if not using the default setting).
2. Edit a doc page.
3. Add a named anchor anywhere on the page. E.g., `
Some Text`
2. Add a link to the named anchor, e.g., `[Link Text](#anchor)`
4. Save the page.
5. Build the site (`yarn build`).

### Expected behavior

No console feedback. `onBrokenAnchors` ignores the arbitrary named anchor because it's only supposed to work for anchors declared with the `Heading` component.

### Actual behavior

`onBrokenAnchors` reports the named anchor as a broken anchor. Example:

```
[WARNING] Docusaurus found broken anchors!

Please check the pages of your site in the list below, and make sure you don't reference any anchor that does not exist.
Note: it's possible to ignore broken anchors with the 'onBrokenAnchors' Docusaurus configuration, and let the build pass.

Exhaustive list of all broken anchors found:
- Broken anchor on source page path = /user-types-and-permissions:
-> linking to #anchor (resolved as: /user-types-and-permissions#anchor)
```

Note that on the rendered page, the anchor works.

### Your environment

- Public source code:
- Public site URL: (issue encountered locally during build)
- Docusaurus version used: 3.1.1
- Environment name and version (e.g. Chrome 89, Node.js 16.4): Version 120.0.6099.129 (Official Build) (arm64)
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): macOS Ventura 13.4.1 (22F82)

### Self-service

- [ ] I'd be willing to fix this bug myself.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。