redocusaurus icon indicating copy to clipboard operation
redocusaurus copied to clipboard

Redocusaurus should collect heading ids / anchors

Open slorber opened this issue 1 year ago • 2 comments

Hi

With Docusaurus v3.1 we introduced a broken anchors checker:

https://docusaurus.io/blog/releases/3.1#broken-anchors-checker

https://docusaurus.io/docs/docusaurus-core#useBrokenLinks

This requires collecting anchors for headings you create, otherwise Docusaurus doesn't know about those created anchors.

CleanShot 2024-01-08 at 15 43 17@2x

Note this api exists in Docusaurus 3.1 but not in 3.0 so you probably want to release a new major version requiring Docusaurus 3.1 to support this.


See also a Docusaurus user that gets reported Redocusaurus anchors links as broken:

https://github.com/facebook/docusaurus/issues/6810#issuecomment-1879387076

slorber avatar Jan 08 '24 14:01 slorber

Thanks @slorber for forwarding the issue! I'll try to look into what API redoc makes available to get the anchor ids but since the rendering is done mostly by redoc and not by this plugin it's possible that this is unfixable. Will try still

rohit-gohri avatar Jan 09 '24 10:01 rohit-gohri

I understand.

Isn't there a way to know the heading its ahead of time by using AppStore or the spec file?

You don't have to call collectAnchor(anchor) in a heading component, you can do this at any level.

const {collectAnchor} = useBrokenLinks();
const anchors = getAnchorsFromSpec(spec);
anchors.forEach(collectAnchor);

The question is: can getAnchorsFromSpec(spec) be implemented?

slorber avatar Jan 09 '24 12:01 slorber