Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Generate proper markdown heading for API docs (enabling automatic "Table of Contents" for API pages) #33361

Closed
juanmaguitar opened this issue Jul 12, 2021 · 3 comments · Fixed by #33381

Comments

@juanmaguitar
Copy link
Contributor

juanmaguitar commented Jul 12, 2021

What problem does this address?

In the automatic generated DOCS for API details ( for example: https://github.com/WordPress/gutenberg/blob/trunk/docs/reference-guides/data/data-core.md ) the elements being documented (such as methods, selectors, action creators and so) are being generated as links and not as headings (with proper level)

# WordPress Core Data
Namespace: `core`.
## Selectors
<!-- START TOKEN(Autogenerated selectors|../../../../packages/core-data/src/selectors.js) -->
<a name="canUser" href="#canUser">#</a> **canUser**
Returns whether the current user can perform the given action on the given
REST resource.
Calling this may trigger an OPTIONS request to the REST API via the
`canUser()` resolver.

This final markup doesn't allow to generate automatic Table of Contents for each page (with tools such as markdown-toc)

What is your proposed solution?

In general, I think having Table of Contents sections in these API’s pages would help people to process and access the information in

I think having these links generated as proper headings levels for each item being documented (each selector in this case) would result in a more correct markdown while also enabling automatically generated Table of Contents for each API page

@juanmaguitar
Copy link
Contributor Author

juanmaguitar commented Jul 12, 2021

The file in charge of orchestrating this transformation seems to be bin/api-docs/update-api-docs.js that internally uses the @wordpress/docgen package

@juanmaguitar
Copy link
Contributor Author

I think this issue is related with #14341

@oandregal
Copy link
Member

I think this change should be fine: it doesn't hurt to try, we can always revert if the result is not adequate.

For context, I presume we used links to allow adding links to the code, which we did at the beginning, and also to make the declarations bookmarkable in the three environments the docs are rendered: the block editor handbook, GitHub, and the npm packages. I've just checked and both the block editor handbook and GitHub auto-generate links to the headings, so having specific links is no longer necessary. npm doesn't but also the existing links don't work as bookmarks due to how npm parses the README file of packages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants