Skip to content

chore: added markdown docs templates#220

Closed
stevedylandev wants to merge 39 commits into
OpenZeppelin:masterfrom
stevedylandev:master
Closed

chore: added markdown docs templates#220
stevedylandev wants to merge 39 commits into
OpenZeppelin:masterfrom
stevedylandev:master

Conversation

@stevedylandev

@stevedylandev stevedylandev commented Oct 31, 2025

Copy link
Copy Markdown

31/10/2025:

This PR adds the updated templates-md and config-md.js to the docs directory. By doing this we can generate API documentation for OpenZeppelin/docs remotely. Please see the guide here

Update (18/12/2025):

  • Removes adoc in favor of markdown
  • Removes Antora.yml
  • Reworks the templates
  • Adds a github workflow for automation
  • Since the docs are now a separate Next.js project, a simple oz-docs.sh bash script is used in favor of docs-utils, which clones the @openzeppelin/docs repository and runs it locally with a chokidar watcher that re-prepares and syncs the docs into the local docs project on changes for a hot refresh experience.

@stevedylandev stevedylandev requested a review from a team as a code owner October 31, 2025 04:30
@coderabbitai

coderabbitai Bot commented Oct 31, 2025

Copy link
Copy Markdown

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The pull request title "chore: added markdown docs templates" accurately describes the main objective of this changeset. The PR adds a new markdown documentation template system with several new files (contract.hbs, page.hbs, helpers.js, properties.js, and config-md.js) to enable API documentation generation. The title is specific and clearly communicates the primary change—adding markdown documentation templates—in a concise manner that a teammate scanning the commit history would immediately understand. The title is neither vague nor misleading and directly reflects the content of the changeset.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

♻️ Duplicate comments (1)
docs/templates-md/properties.js (1)

23-29: Code duplication and null safety issue.

This code duplicates the signature-building logic from the anchor function and has the same null safety concerns.

See the refactor suggestion in the previous comment (lines 10-16) which addresses both issues by extracting common logic and adding null checks.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b358b3 and f41f1b0.

📒 Files selected for processing (6)
  • docs/config-md.js (1 hunks)
  • docs/templates-md/contract.hbs (1 hunks)
  • docs/templates-md/helpers.js (1 hunks)
  • docs/templates-md/page.hbs (1 hunks)
  • docs/templates-md/properties.js (1 hunks)
  • hardhat.config.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
hardhat.config.js (2)
docs/templates-md/helpers.js (2)
  • require (1-1)
  • require (4-4)
docs/templates-md/properties.js (2)
  • require (1-1)
  • require (2-2)
docs/templates-md/properties.js (1)
docs/templates-md/helpers.js (2)
  • slug (67-72)
  • i (139-139)
docs/templates-md/helpers.js (1)
docs/templates-md/properties.js (5)
  • require (1-1)
  • require (2-2)
  • item (83-83)
  • signature (11-11)
  • signature (24-24)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: slither
  • GitHub Check: tests-foundry
  • GitHub Check: coverage
  • GitHub Check: tests
🔇 Additional comments (3)
docs/templates-md/properties.js (3)

59-65: LGTM! Good defensive coding.

The ternary operator properly handles the case where item.variables doesn't exist, preventing potential runtime errors.


67-72: LGTM!

The function correctly aggregates publicly visible functions and public variables using AST queries with appropriate visibility filters.


47-57: Add null safety checks for item.inheritance.

All three functions assume item.inheritance exists and is an array. If it's undefined, calling .some() will throw a runtime error.

Apply this diff to add defensive checks:

 module.exports['has-functions'] = function ({ item }) {
-  return item.inheritance && item.inheritance.some(c => c.functions.length > 0);
+  return item.inheritance?.some(c => c.functions?.length > 0) ?? false;
 };
 
 module.exports['has-events'] = function ({ item }) {
-  return item.inheritance && item.inheritance.some(c => c.events.length > 0);
+  return item.inheritance?.some(c => c.events?.length > 0) ?? false;
 };
 
 module.exports['has-errors'] = function ({ item }) {
-  return item.inheritance && item.inheritance.some(c => c.errors.length > 0);
+  return item.inheritance?.some(c => c.errors?.length > 0) ?? false;
 };

Likely an incorrect or invalid review comment.

Comment thread docs/templates-md/contract.hbs Outdated
Comment thread docs/templates-md/contract.hbs Outdated
Comment thread docs/templates-md/properties.js Outdated
Comment thread docs/templates-md/properties.js Outdated
Comment thread docs/templates-md/properties.js Outdated
Comment thread docs/templates-md/properties.js Outdated
- Updated all README.adoc to README.mdx
- Moved `templates-md` and the contents to just `templates`
- Updated `hardhat.config.js` to use `docs/config`
- Updated `helpers.js` to account for adoc change
- Updated `docs/config.js` to use mdx
Updated the following legacy patterns:
- `https://url[Link Text]` -> `[Link Text](https://url)`
- `WARNING: | IMPORTANT: | CAUTION: | IMPORTANT:` -> `<Callout
type=warn"></Callout>`
- `NOTE: | TIP:` -> <Callout></Callout>
- Delimitters such as `====` -> `####` or removed if no header text
present
@stevedylandev

stevedylandev commented Nov 18, 2025

Copy link
Copy Markdown
Author

Updated the following legacy patterns in the natspec:

  • https://url[Link Text] -> [Link Text](https://url)
  • WARNING: | IMPORTANT: | CAUTION: | IMPORTANT: -> <Callout type=warn"></Callout>
  • NOTE: | TIP: ->
  • Delimitters such as ==== -> #### or removed if no header text
    present

With the adoc conversion to mdx in addition to these changes to the natspec we were able to simplify docs/helpers.js. While it is still a fair bit larger than the original version, much of this was necessary to make docgen work with markdown syntax and keeping cross reference links.

Comment thread docs/templates/helpers.js
return `${pagePath}#${anchor}`;
}

// Process {REF} and other references

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So most replacing logic can be removed now right?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for this repo we could remove pieces like L:146-149 and maybe L:157-162, but these are patterns used in other libraries. We definitely still need L:151-155 and the rest of functions to handle instances where a contract references another contract, .e.g. you might have {ERC20} inside ERC1155 comments and we need to turn that into a markdown link.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also remove L:146-149

Comment thread contracts/account/modules/ERC7579DelayedExecutor.sol Outdated
Comment thread scripts/prepare-docs.sh Outdated
Comment thread scripts/prepare-docs.sh Outdated
Comment thread scripts/prepare-docs.sh Outdated
Comment thread .github/workflows/trigger-docs-generation.yml Outdated
Comment thread .github/workflows/trigger-docs-generation.yml Outdated
Comment thread .github/workflows/trigger-docs-generation.yml Outdated
Comment thread .github/workflows/trigger-docs-generation.yml Outdated
Co-authored-by: James Toussaint <33313130+james-toussaint@users.noreply.github.com>
@gonzaotc

Copy link
Copy Markdown
Contributor

I honestly do not like the NatSpec changes of TIP, WARNING and NOTE into writting HTML components inside our contracts. While it remains functional, I think it looks much worse for a human reading the contracts directly. Therefore, I think the parsing into HTML components should happen outside of the contracts and maintain human-first readability.

@james-toussaint

Copy link
Copy Markdown
Collaborator

I honestly do not like the NatSpec changes of TIP, WARNING and NOTE into writting HTML components inside our contracts. While it remains functional, I think it looks much worse for a human reading the contracts directly. Therefore, I think the parsing into HTML components should happen outside of the contracts and maintain human-first readability.

Yes, at the very beginning I thought changing these were the only things required for the API doc migration so why not doing it, but afterward considering the later high templating/processing, I would also like to come back to the original NatSpec 👍

james-toussaint and others added 10 commits December 15, 2025 14:35
Co-authored-by: James Toussaint <33313130+james-toussaint@users.noreply.github.com>
Co-authored-by: James Toussaint <33313130+james-toussaint@users.noreply.github.com>
Co-authored-by: James Toussaint <33313130+james-toussaint@users.noreply.github.com>
@gonzaotc

Copy link
Copy Markdown
Contributor

Just automated the watch mode so changes are hot-refreshed on the local copy of the docs repository. Also added cache so it is updated instead of being re-clonned each time docs are run

gonzaotc
gonzaotc previously approved these changes Dec 18, 2025
@gonzaotc gonzaotc requested review from Amxx, arr00 and ernestognw and removed request for arr00 December 18, 2025 20:27
ernestognw
ernestognw previously approved these changes Dec 18, 2025

@ernestognw ernestognw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaving some observations and recommendations but I don't want to block the PR. There may be still some details in how we're processing the docs but we can sort them out easily as long as we have a preview for future PRs.

Comment thread package.json
Comment thread docs/templates/helpers.js Outdated
Comment thread docs/templates/helpers.js
Comment thread docs/templates/helpers.js

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't checked personally but I feel there might be orphan exported functions here now that we changed the contract.hbs and page.hbs. It may be good to do a cleanup of this and the properties.js file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least internal-variables things got removed from documentation, do you confirm we don't need it in the final public documentation?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They're not referenced in the docs repo, and also these should apply only to the templates in this repo so I think it's safe to remove them

Comment thread docs/templates/helpers.js Outdated
Comment thread docs/templates/helpers.js Outdated
Co-authored-by: Ernesto García <ernestognw@gmail.com>
@ernestognw

Copy link
Copy Markdown
Member

Closing in favor of #225

@ernestognw ernestognw closed this Dec 22, 2025
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 this pull request may close these issues.

4 participants