Skip to content

fix: make Mermaid rendering responsive - #246

Open
teng-lin wants to merge 1 commit into
RivoLink:mainfrom
teng-lin:agent/fix-responsive-mermaid-layout
Open

fix: make Mermaid rendering responsive#246
teng-lin wants to merge 1 commit into
RivoLink:mainfrom
teng-lin:agent/fix-responsive-mermaid-layout

Conversation

@teng-lin

Copy link
Copy Markdown

What changed

  • Make Mermaid rendering aware of the actual content width, including list and blockquote prefixes plus the surrounding frame.
  • Keep the authored Mermaid layout when it fits.
  • Retry oversized left-to-right flowcharts vertically before falling back.
  • Retry oversized class diagrams horizontally when that produces a valid fit.
  • Render class diagrams that still cannot fit as vertically stacked class cards followed by a compact relationship list.
  • Fall back to syntax-highlighted Mermaid source when a valid two-dimensional render cannot fit safely, instead of wrapping rendered rows.
  • Add demo.md with reproducible horizontal-flowchart and large-class-diagram examples.

Why

Mermaid output is a pre-rendered two-dimensional text canvas. Leaf previously passed oversized diagram rows through the generic code-block wrapper. Wrapping those rows preserved the characters but broke their spatial relationships, splitting box borders, labels, and connectors across unrelated terminal rows.

A width guard prevents that corruption, but source fallback alone means large class diagrams no longer render at ordinary terminal widths. Class graphs with many wide cards and fan-out relationships can remain hundreds of columns wide in every graphical orientation.

This change treats Mermaid layout as responsive content. It tries alternate graph orientations when useful and uses a vertical class representation when no graphical orientation can fit. Class names, stereotypes, members, and authored relationships remain visible and searchable while the output grows downward instead of beyond the viewport.

User impact

  • Narrow terminals no longer show mangled Mermaid boxes and arrows.
  • Wide terminals continue to receive the normal graphical rendering.
  • Large class diagrams remain rendered and readable at common terminal widths rather than appearing as raw Mermaid source.
  • Invalid or unsupported diagrams retain the existing source fallback.

Validation

  • cargo fmt --all -- --check
  • cargo test — 416 passed
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo build --release
  • Manually rendered demo.md at 80 columns
  • Manually rendered a 196 KB API design document containing the reported large class diagram at 80, 120, 240, and 320 columns

@teng-lin
teng-lin marked this pull request as ready for review August 13, 2026 21:31

@RivoLink RivoLink left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Hi,
Sorry for the delay, and thank you for your interest in the project and for this PR.

I have a few requests:

  • Rebase from main and fix the CI check failure by adding : to the commit message: fix: responsive Mermaid layout
  • Maybe remove the demo.md file from the commit and attach it to this PR instead.
  • GPG signing is required on the main branch, so if you can sign it, great. If not, no worrie, I'll handle it while preserving you as the author.

GPG signing docs : https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

Thanks!

Comment thread demo.md
@@ -0,0 +1,85 @@
# Responsive Mermaid rendering

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Maybe remove this file from the commit and attach it to the PR

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.

2 participants