Skip to content

ci/docs: escape MDX-incompatible patterns and add -subdir to gen-docs#1112

Open
chaptersix wants to merge 3 commits into
temporalio:mainfrom
chaptersix:docs/gen-docs-mdx-fixes
Open

ci/docs: escape MDX-incompatible patterns and add -subdir to gen-docs#1112
chaptersix wants to merge 3 commits into
temporalio:mainfrom
chaptersix:docs/gen-docs-mdx-fixes

Conversation

@chaptersix

@chaptersix chaptersix commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

This consolidates the excellent groundwork in #980, #1076, and #981 into a single change, and verifies the result against a real Docusaurus 3.10.1 build. Huge thanks to @lennessyy — the approach here is entirely built on those PRs; this just stitches them together and irons out a few interactions between them.

gen-docs now escapes the patterns that break Docusaurus MDX (JSX) compilation, on every path that writes a command description (including the new split paths):

  • bare angle-bracket placeholders in prose (e.g. <base64-encoded-cert>, <key>) → \<...\>
  • single-quoted JSON examples (e.g. '{"a":"b"}', 'Key={"a":"b"}') → braces escaped in body text, backticked in option tables
  • custom heading IDs (e.g. ## Heading {#id}) → {/* #id */}, the form that compiles under Docusaurus 3.10 and still produces the custom anchor

Fenced code blocks and inline code spans are left untouched.

It also adds the -subdir flag (subcommands of the named command are written to a subdirectory, e.g. -subdir cloudcloud/*.mdx, with deeper subcommands nested as headings), and a generic auto-generated notice.

What changed relative to the existing PRs

All three PRs were on the right track. The differences here are about how they interact:

Companion PR

temporalio/documentation#4836

@chaptersix chaptersix requested a review from a team as a code owner July 7, 2026 15:41
@chaptersix chaptersix marked this pull request as draft July 7, 2026 15:46
@chaptersix chaptersix force-pushed the docs/gen-docs-mdx-fixes branch 2 times, most recently from ee208c9 to c76b195 Compare July 7, 2026 15:51
Generated MDX docs contain patterns that are valid CommonMark but break
Docusaurus MDX (JSX) compilation under Docusaurus 3.10+:

- bare angle-bracket placeholders in prose (e.g. <base64-encoded-cert>,
  <key>), which MDX parses as unclosed JSX/HTML tags;
- curly braces in single-quoted JSON examples (e.g. '{"a":"b"}'), which
  MDX parses as JSX expressions; and
- custom heading IDs (e.g. "## Heading {#id}"), which MDX parses as a JSX
  expression and rejects with "Could not parse expression with acorn".

Add escapeMDXDescription() and apply it to every path that writes a
command description (including the new split paths), leaving fenced code
blocks and inline code spans untouched. Custom heading IDs are converted
to Docusaurus's MDX comment form ({/* #id */}), which compiles and still
produces the custom anchor. Unify the JSON-escaping regex so
encodeJSONExample (option table cells) also matches both 'Key={...}' and
standalone '{...}' forms.

Add a -subdir flag so a command's subcommands can each be written to their
own file within a subdirectory (e.g. -subdir cloud produces cloud/*.mdx),
which the cloud CLI extension needs to avoid a single ~2800-line page.
Deeper subcommands nest as headings within their parent's file. Index and
landing pages are intentionally not generated, since the docs site
hand-maintains them (custom ordering, embedded components).

Replace the hardcoded (and incorrect) source path in the auto-generated
notice with a generic message, since inputs can come from multiple repos.

Add unit tests for the escaping functions and subdir generation. Verified
the generated output compiles with a real Docusaurus 3.10.1 build.
@chaptersix chaptersix force-pushed the docs/gen-docs-mdx-fixes branch from c76b195 to 75ae654 Compare July 7, 2026 15:57
@chaptersix chaptersix marked this pull request as ready for review July 7, 2026 17:13
@ks-temporal ks-temporal requested a review from Copilot July 7, 2026 18:06

Copilot AI 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.

Pull request overview

This PR updates the gen-docs generator to better support Docusaurus MDX output by escaping MDX-incompatible patterns in generated descriptions, and adds a -subdir flag to split large command trees into per-subcommand files under a directory.

Changes:

  • Add -subdir flag to cmd/gen-docs and route split command output into subdir/*.mdx (creating directories as needed).
  • Apply MDX-escaping to command description prose (while preserving fenced/inline code) and unify JSON-in-single-quotes handling.
  • Add unit tests covering MDX escaping, JSON example encoding, and -subdir splitting behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
internal/commandsgen/docs.go Implements -subdir splitting, generic auto-generated notice, and MDX escaping for descriptions.
internal/commandsgen/docs_test.go Adds tests for MDX escaping, JSON example encoding, and split output generation.
cmd/gen-docs/main.go Wires up -subdir flag and ensures split output directories exist before writing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/commandsgen/docs.go Outdated
Comment thread internal/commandsgen/docs.go
Addresses review feedback on the -subdir output:

- Direct-child leaf pages (e.g. cloud login) now go through the same
  writeLeafOptions path as deeper leaves, so they render a Global Flags
  section instead of silently omitting it. writeLeafOptions now only emits
  the "#global-flags" link when inherited options actually exist, so a leaf
  with no inherited options can't link to an anchor that isn't generated.
- Non-leaf split pages (e.g. cloud namespace) now include the command's own
  description before the boilerplate, matching how non-split subcommand
  pages render it.

Split subcommand headings keep the path relative to the split root
(e.g. "ha update", "cert-ca create") rather than only the final segment:
within one aggregated file that keeps each heading's anchor unique and
stable, which other docs link to (e.g. /cloud/high-availability/enable ->
cloud/namespace#ha-update). Verified with a Docusaurus 3.10.1 build.

@ks-temporal ks-temporal 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.

Looks good. I left some suggestions, mostly to update code comment.

Comment thread internal/commandsgen/docs.go
Comment thread internal/commandsgen/docs.go
Comment thread internal/commandsgen/docs.go Outdated
Comment thread internal/commandsgen/docs.go
…cal)

- Note that FullName segments are single-space separated (ancestor routing).
- Document that a multi-word split root is hyphenated into one directory.
- Use c.FullName directly instead of re-joining the split parts.
- Note that code-fence markers are assumed to start their own line.

No change to generated output.
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.

3 participants