rohit-gohri / redocusaurus

OpenAPI for Docusaurus with Redoc
https://redocusaurus.vercel.app/
MIT License
600 stars 111 forks source link

Redocusaurus should collect heading ids / anchors #321

Open slorber opened 6 months ago

slorber commented 6 months ago

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

rohit-gohri commented 5 months ago

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

slorber commented 5 months ago

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?