Skip to content

feat: custom prettier plugin to correctly format inline MDX components#29770

Merged
mvvmm merged 5 commits intoproductionfrom
mdx-formatting
Apr 13, 2026
Merged

feat: custom prettier plugin to correctly format inline MDX components#29770
mvvmm merged 5 commits intoproductionfrom
mdx-formatting

Conversation

@mvvmm
Copy link
Copy Markdown
Contributor

@mvvmm mvvmm commented Apr 11, 2026

Summary

Adds a custom prettier plugin (prettier-plugin-mdx-inline) that prevents prettier from wrapping <code> and <GlossaryTooltip> children onto new lines in MDX files.

The problem: Prettier's MDX formatter treats standalone JSX elements as block-level and wraps their children onto new lines when they exceed printWidth. MDX v2+ interprets those newlines as markdown paragraph boundaries, injecting <p> tags inside inline elements — producing broken HTML like <code><p>...</p></code>. This is a known MDX behavior (mdx-js/mdx#1798) and prettier's MDX parser does not yet account for it (prettier/prettier#12209 tracks MDX v3 support which may eventually resolve this). The codebase relied on 41 prettier-ignore comments to work around it.

The fix: The plugin wraps prettier's built-in MDX parser and converts matching JSX AST nodes to opaque HTML nodes that prettier outputs verbatim. It also collapses any existing multi-line formatting (from previous prettier runs) back to a single line. The element list is configurable via mdxInlineElements in .prettierrc.mjs.

What changed in content files:

  • Removed all 41 prettier-ignore comments that were guarding <code> and <GlossaryTooltip> elements
  • Collapsed 7 already-broken multi-line <code> blocks back to single lines (these had been reformatted by prettier in the past without prettier-ignore protection)
  • No content changes — only formatting and comment removal

Performance: Negligible overhead (~60ms across 231 files, within run-to-run noise).

Images

Here are just two examples...

Before

https://developers.cloudflare.com/durable-objects/best-practices/websockets/

Screenshot 2026-04-11 at 6 47 00 PM

https://developers.cloudflare.com/durable-objects/api/base/

Screenshot 2026-04-11 at 6 52 48 PM

After

https://mdx-formatting.preview.developers.cloudflare.com/durable-objects/best-practices/websockets/

Screenshot 2026-04-11 at 6 47 05 PM

https://mdx-formatting.preview.developers.cloudflare.com/durable-objects/api/base/

Screenshot 2026-04-11 at 6 52 53 PM

@github-actions github-actions bot added product:workers Related to Workers product product:ruleset-engine product:api-shield product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ product:workflows Workflows: https://developers.cloudflare.com/workflows/ size/m labels Apr 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
* @cloudflare/pcx-technical-writing, @cloudflare/product-owners
/src/content/docs/api-shield/ @patriciasantaana, @cloudflare/pcx-technical-writing, @cloudflare/product-owners
/src/content/docs/durable-objects/ @elithrar, @vy-ton, @joshthoward, @oxyjun, @lambrospetrou, @mikenomitch, @cloudflare/pcx-technical-writing, @cloudflare/product-owners
/src/content/docs/ruleset-engine/ @pedrosousa, @cloudflare/pcx-technical-writing, @cloudflare/product-owners
/src/content/docs/workers/ @cloudflare/workers-docs, @GregBrimble, @irvinebroque, @mikenomitch, @korinne, @WalshyDev, @cloudflare/deploy-config, @cloudflare/pcx-technical-writing, @cloudflare/product-owners, @cloudflare/wrangler, @mattietk, @cloudflare/dev-plat-leads
/src/content/docs/workflows/ @elithrar, @celso, @mia303, @jonesphillip, @cloudflare/pcx-technical-writing, @cloudflare/product-owners

@mvvmm mvvmm changed the title feat: prettier plugin to prevent inline MDX element reformatting feat: custom prettier plugin to prevent inline MDX element reformatting Apr 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 11, 2026

Preview URL: https://5dc034f6.preview.developers.cloudflare.com
Preview Branch URL: https://mdx-formatting.preview.developers.cloudflare.com

Files with changes (up to 15)

Original Link Updated Link
https://developers.cloudflare.com/durable-objects/best-practices/websockets/ https://mdx-formatting.preview.developers.cloudflare.com/durable-objects/best-practices/websockets/
https://developers.cloudflare.com/ruleset-engine/rules-language/functions/ https://mdx-formatting.preview.developers.cloudflare.com/ruleset-engine/rules-language/functions/
https://developers.cloudflare.com/durable-objects/api/base/ https://mdx-formatting.preview.developers.cloudflare.com/durable-objects/api/base/
https://developers.cloudflare.com/api-shield/security/schema-validation/ https://mdx-formatting.preview.developers.cloudflare.com/api-shield/security/schema-validation/
https://developers.cloudflare.com/workflows/build/workers-api/ https://mdx-formatting.preview.developers.cloudflare.com/workflows/build/workers-api/
https://developers.cloudflare.com/workers/runtime-apis/bindings/worker-loader/ https://mdx-formatting.preview.developers.cloudflare.com/workers/runtime-apis/bindings/worker-loader/
https://developers.cloudflare.com/api-shield/security/jwt-validation/ https://mdx-formatting.preview.developers.cloudflare.com/api-shield/security/jwt-validation/
https://developers.cloudflare.com/workers/runtime-apis/nodejs/asynclocalstorage/ https://mdx-formatting.preview.developers.cloudflare.com/workers/runtime-apis/nodejs/asynclocalstorage/
https://developers.cloudflare.com/workflows/python/python-workers-api/ https://mdx-formatting.preview.developers.cloudflare.com/workflows/python/python-workers-api/

@mvvmm
Copy link
Copy Markdown
Contributor Author

mvvmm commented Apr 12, 2026

Checked each of the files output myself, and they all look correct.

@mvvmm mvvmm marked this pull request as ready for review April 12, 2026 00:03
@mvvmm mvvmm changed the title feat: custom prettier plugin to prevent inline MDX element reformatting feat: custom prettier plugin to correctly format inline MDX components Apr 12, 2026
Copy link
Copy Markdown
Member

@kentonv kentonv left a comment

Choose a reason for hiding this comment

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

Nice, thanks!

ctdsf pushed a commit to ctdsf/cloudflare-docs that referenced this pull request Apr 13, 2026
* Remove global-level for aws-alb doc: partially addresses cloudflareGH-29770

* AI-assisted: split zone-level to account for global and vet API links

* AI-assisted: add <Tabs> pattern and Dash instructions

* Move note on encryption mode higher and use callout

* Manual: tighten up information in index and clarify cert priority

* Manual: tighten up information in index and clarify cert priority

* Fix e.g. and replace operation links with actual endpoint names

* Update other how-tos affected with page re-org

* AI-assisted: check against cloudflareGH-29400 and bring improvements

* Improve text in index.mdx and update zone-level steps

* More deatils on the per-hostname steps

* AI-assited: inspect related docs and improve aws-alb-integration

* Update per-hostname with no toggle and API in manage-certs

* Apply suggestions from code review

Co-authored-by: Jun Lee <junlee@cloudflare.com>

---------

Co-authored-by: Jun Lee <junlee@cloudflare.com>
@mvvmm mvvmm merged commit 20be250 into production Apr 13, 2026
11 checks passed
@mvvmm mvvmm deleted the mdx-formatting branch April 13, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:api-shield product:durable-objects Durable Objects: https://developers.cloudflare.com/workers/learning/using-durable-objects/ product:ruleset-engine product:workers Related to Workers product product:workflows Workflows: https://developers.cloudflare.com/workflows/ size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.