fix(docs): escape MDX braces in generated reference pages - #90
Merged
Conversation
Docusaurus parses the generated reference pages as MDX, where a bare
`{...}` is a JSX expression rather than literal text. Any schema
description containing braces therefore breaks the docs build:
Error: Can't render static file for pathname "/reference/module_port"
cause: Objects are not valid as a React child
(found: object with keys {children, exports})
`module` happens to be a real binding in MDX module scope, so a NetBox
port-name token like `Ethernet{module}/1` renders the MDX module object
rather than failing loudly on an undefined name.
Nothing on main trips this today, so this commit changes no generated
output - it removes a trap. The `validate-documentation` job is the only
thing that catches it, and it runs after `Check generated documentation
is up to date`, which passes happily because the regenerated MDX matches
the committed MDX. The docs are consistently generated and consistently
unbuildable.
tasks/docs.py
Escape braces in everything rendered as MDX prose or into a Markdown
table, leaving the `code` section alone - it lands inside a fenced
block, where MDX ignores braces and an escape would show up verbatim
in the rendered YAML.
Inline code spans are skipped too. Braces inside them are already
inert, and a backslash there renders literally rather than escaping,
so blindly escaping would corrupt a description that had already
worked around this by using backticks.
tests/, pyproject.toml, .github/workflows/ci.yml
The escaping rules above are subtle enough to regress unnoticed, so
they get unit tests - the repo's first. Adds pytest to the dev group,
points it at the repo root so the top-level `tasks` package imports,
and runs it in the existing python-lint job.
Verified by temporarily giving a description an unbackticked
`Ethernet{module}/1`: before, the docs build fails as above; after, it
builds and renders the literal braces, with the code fence untouched.
Deploying schema-library with
|
| Latest commit: |
2483d11
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://3bcce2bd.schema-library.pages.dev |
| Branch Preview URL: | https://fix-docs-mdx-brace-escaping.schema-library.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Docusaurus parses the generated reference pages as MDX, where a bare
{...}is a JSX expression rather than literal text. Any schema description containing braces breaks the docs build:modulehappens to be a real binding in MDX module scope, so a NetBox port-name token likeEthernet{module}/1silently renders the MDX module object instead of failing on an undefined name.Found while rebasing #76, whose
module_portextension is the first schema in the library to put braces in a description.Why the existing CI doesn't protect against this
Check generated documentation is up to datepasses happily, because the regenerated MDX matches the committed MDX — the docs are consistently generated and consistently unbuildable. Onlyvalidate-documentation, which runs afterwards, catches it. Anyone writing a braced description hits this at the very end of a CI run, with an error that names React rather than their schema.Changes
tasks/docs.pyEscape braces in everything rendered as MDX prose or into a Markdown table. Two things are deliberately left alone:
codesection. It lands inside a fenced block, where MDX ignores braces and an escape would show up verbatim in the rendered YAML. This matters — several schemas havejinja2_template: "{{ device__name__value }}", which must survive intact.module_portdoes in feat(dcim): support NetBox device-type and module-type imports #76).tests/,pyproject.toml,.github/workflows/ci.ymlThose two carve-outs are subtle enough to regress unnoticed, so they get unit tests — the repo's first. Adds
pytestto the dev group, points it at the repo root so the top-leveltaskspackage imports, and runs it in the existingpython-lintjob.Verification
This changes no generated output. No description on
maincontains braces today, so regenerating produces a zero-line diff. It removes a trap rather than fixing a visible symptom.Proven by temporarily giving
extensions/cable/cable.ymlan unbackticked description:Generated MDX — escaped in prose, untouched in the code fence:
npm run buildthen succeeds where it previously failed, and the rendered HTML contains the literalEthernet{module}/1 plus {a}with zero[object Object]and no leaked backslashes. Probe reverted before committing.ruff,ruff format,mypy,pylint(10.00/10),yamllintand 12 unit tests all pass.Notes for reviewers
python-lintjob. If you'd rather tests live in their own job, or not run in CI yet, that step is trivially droppable without touching the fix.invoke docs.generatealso overwrites everyextensions/*/README.mdwith a fixed stub, clobbering hand-written notes inlocation_minimal,location_siteandrack. Anddocs/docs/reference/security.mdxis stale against its schema. Both are separate pre-existing issues.