facebook / facebook/docusaurus

onBrokenAnchors reports named anchor tags as broken links

Abierto
#9,808 25 comentarios 3 reacciones 0 asignados Ver en GitHub
bug
Lenguaje dominante
TypeScript
Estrellas
66.2k
Forks
10k
Merge medio
1 d 3 h
PR fusionados (30 d)
52

Descripción

### 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.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.