mermaid: The other half of #57967 (#58419)

I was a silly goose didn't notice my `git push` failed, so merged #57967
without a critical commit, and some follow-ups.

This PR just cherry-picks those commits.

Release Notes:

- N/A or Added/Fixed/Improved ...
a5f0dc322dCameron Mcloughlin committed on 6/3/2026, 2:10:43 PM· committed by GitHubparent3f0d233
9 files changedLine totals unavailable