Skip to content

Conversation

@irvinebroque
Copy link
Contributor

@irvinebroque irvinebroque commented Dec 30, 2025

  • agents increasingly consume our documentation
  • mermaid diagrams are easier for language models to parse and understand than static images
  • Mermaid's text-based format allows models to extract relationships, flows, and architectural patterns
  • Mermaid diagrams lacked proper styling and didn't meet the visual polish expected in our documentation

This PR enhances mermaid diagram rendering with:

  • Cloudflare branding: Custom theme using our brand orange (#f6821f) and color palette (cl1-orange, cl1-gray)
  • Light/dark theme support: Automatic re-rendering when users switch themes
  • Annotation footers: Professional footer with diagram title (from accTitle) and Cloudflare logo
  • Improved typography: Uses Starlight's font stack for consistency
  • Better accessibility: Proper contrast ratios and support for screen reader descriptions (accDescr)

Examples

Before:

Screenshot 2025-12-30 at 10 35 18 AM Screenshot 2025-12-30 at 10 35 24 AM Screenshot 2025-12-30 at 10 42 08 AM

After:

Screenshot 2025-12-30 at 10 34 59 AM Screenshot 2025-12-30 at 10 35 05 AM Screenshot 2025-12-30 at 10 25 19 AM

Notes

Why some values are hardcoded: The styling logic currently lives in TypeScript (src/scripts/mermaid.ts) since mermaid's theme configuration requires JavaScript initialization. Hex codes and specific style values are hardcoded for:

  • Theme variables (primaryColor, borderColor, etc.)
  • Cloudflare brand colors (cl1-orange-9, cl1-gray-0, etc.)
  • Font family extracted from CSS variables

This seemed like the simplest starting point. If there's a better approach to make these values more maintainable (e.g., extracting to a config file or reading more from CSS custom properties), I'm open to refactoring.

Files changed

  • src/scripts/mermaid.ts: Enhanced rendering with custom theme variables, wrapper containers, and annotation footers
  • src/styles/mermaid.css: Container styles, annotation footer styling, dark mode adjustments
  • src/scripts/MERMAID.md: New documentation for usage, customization, and troubleshooting

Document microfrontend architecture using router workers and service bindings, including routing logic, path rewriting, asset handling, preloading, and deployment workflows.
@github-actions
Copy link
Contributor

github-actions bot commented Dec 30, 2025

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

Pattern Owners
* @cloudflare/pcx-technical-writing
*.ts @cloudflare/pcx-content-engineering, @cloudflare/content-engineering, @kodster28

@irvinebroque irvinebroque changed the title Bib/mermaid Prettify mermaid diagram rendering Dec 30, 2025
@irvinebroque irvinebroque marked this pull request as ready for review December 30, 2025 18:46
@irvinebroque irvinebroque requested review from a team and kodster28 as code owners December 30, 2025 18:46
@github-actions
Copy link
Contributor

@irvinebroque
Copy link
Contributor Author

@cloudflare/pcx-content-engineering thoughts? would love to land this

@TownLake TownLake enabled auto-merge (squash) January 9, 2026 17:15
@colbywhite colbywhite disabled auto-merge January 9, 2026 18:42
Copy link
Collaborator

@colbywhite colbywhite left a comment

Choose a reason for hiding this comment

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

Given the state of our mermaid integration (custom fork, client-side focused), this is likely the most straightforward way to get the custom theme in there. Ideally, Cloudflare's theme(s) would be represented via something like style-dictionary to avoid the hardcoding. Let's merge it for now. I've got comments that may or may not need to be easy to address.

@@ -1,3 +1,75 @@
/* Hide unprocessed diagrams to prevent flash of unstyled content */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sidenote: I don't think this comment is 100% accurate. Instead of a quick shift from the raw diagram text to the svg, this opts for a quick shift from nothing to the svg. Both strategies still flash and result in CLS. This seems like a purposeful decision and thus a bit orthogonal to this PR, but the comment implies that this is preventing any flash.

attributeFilter: ["data-theme"],
});

render();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason this is needed at the root level?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this meant to be a general "How to do mermaid" doc? The accTitle and accDesc recommendation likely makes more sense in the style guide, although I'm not sure where. We might need to create a good spot for it. The rest might be better served in the contributing page in some shape or form.

This loose md file might get lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:workers Related to Workers product size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants