Skip to content

markdown: Update merman renderer to 0.6#57967

Merged
cameron1024 merged 3 commits into
zed-industries:mainfrom
Latias94:merman-0-6-mermaid-render
Jun 3, 2026
Merged

markdown: Update merman renderer to 0.6#57967
cameron1024 merged 3 commits into
zed-industries:mainfrom
Latias94:merman-0-6-mermaid-render

Conversation

@Latias94

Copy link
Copy Markdown
Contributor

Following up on #57644 by @cameron1024, this PR updates merman to v0.6.

With merman 0.6's new raster-safe SVG pipeline, Zed can move generic usvg/resvg cleanup passes out of this crate and rely on merman for them instead.

What's moved to merman:

  • foreignObject fallback text generation
  • Unsupported CSS cleanup
  • Invalid SVG attribute cleanup

What's kept in Zed:

  • Theme CSS injection and accent color assignment
  • Zed-specific fallback overlay handling

Integration note:
In merman v0.6, fallback overlay groups are marked with data-merman-foreignobject="fallback" and preserve source classes like node or section-*, so host CSS can still style fallback text. This PR updates Zed's accent tracker to check for this marker, ensuring fallback overlays are not treated as real layout nodes.

I also added a render-stage test for the new contract: the SVG output from render_mermaid is already raster-safe before Zed-specific post-processing runs.


Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Improved rendering of Mermaid diagrams in Markdown previews.

Tests:

  • cargo +1.95 fmt --check -p mermaid_render
  • cargo +1.95 test -p mermaid_render
  • cargo +1.95 clippy -p mermaid_render --all-targets -- -D warnings
  • git diff --check HEAD~1..HEAD

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label May 28, 2026
@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label May 28, 2026
@maxdeviant maxdeviant changed the title markdown: update merman renderer to 0.6 markdown: Update merman renderer to 0.6 May 28, 2026
@ChristopherBiscardi ChristopherBiscardi added the area:preview/mermaid Feedback for Zed's Mermaid diagram support label May 28, 2026
@cameron1024

Copy link
Copy Markdown
Contributor

Thanks for the PR (and the excellent library)! I'm OOO but will review when I'm back. Would be very happy to remove as much of the post-processing logic as possible, so looking forward to it 😁

@ChristopherBiscardi

Copy link
Copy Markdown
Contributor

Thank you for the update PR!

There seem to be a few significant differences in the rendering after this PR, most notably here are background color and text color:

Before:

Screenshot 2026-06-01 at 8 00 01 PM

After:

Screenshot 2026-06-01 at 7 59 49 PM

@cameron1024

Copy link
Copy Markdown
Contributor

I've pushed a commit to fix the incorrect colors and a few other issues. But if any of that looks redundant given some features of merman 0.6 feel free to change it. This was the minimal change to keep rendering looking how it does today

@Latias94

Latias94 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

Oops, my bad! I was a bit too trigger-happy with deleting those post-processing lines. 😅 Huge thanks to @cameron1024 for the commits to fix this (and honestly, for bringing merman into Zed in the first place!).

I can confirm it works well now.

image

Theming is definitely still a weak point in merman, so keeping Zed's own color compatibility layer makes sense. Feel free to adjust the logic or push directly to this branch if you want!

Longer term, I’ll take these pain points into account and work on proper theme support for merman v0.7, alongside the Mermaid v11.15.0 update. Thanks again!

@cameron1024

Copy link
Copy Markdown
Contributor

Nice! I've been really happy with it, so excited for any improvements 😁

I think the visual output is good now, I'll do a more regular code review later today, but from a quick look already it seems fine.

@cameron1024

Copy link
Copy Markdown
Contributor

FYI, based on #58325, I think we should hold off on merging this PR until that panic is fixed upstream

- switch mermaid_render to published merman 0.6.2\n- refresh Cargo.lock to use crates.io release artifacts
@Latias94

Latias94 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, I have fixed in v0.6.2. I also found the same issue in a few other diagram types (State, Block, Mindmap, Treemap, C4, and Class diagram) and fixed them in the same release.

@cameron1024

cameron1024 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Update on the code: we hit a stack overflow with cyclic diagrams, e.g.:

flowchart TD
  subgraph A
    B
  end
  subgraph B
    A
  end
Loading

This requires a change to merman, which we've pushed to our fork, tagged v0.6.2-with-patches. I've also pushed some other changes to this PR, because we're doing a release and the priority is getting rid of panics. You mentioned that 0.6.2 fixes some extra panics that our fork doesn't currently handle, so I want to include that as well.

Going ahead and merging this. If you feel like my changes are incorrect, happy to discuss in another PR after the release.

Thanks again for the contribution!

@cameron1024 cameron1024 enabled auto-merge June 3, 2026 13:01
@cameron1024 cameron1024 added this pull request to the merge queue Jun 3, 2026
Merged via the queue into zed-industries:main with commit 6d72acd Jun 3, 2026
32 checks passed
@cameron1024

Copy link
Copy Markdown
Contributor

/cherry-pick preview

@Latias94

Latias94 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor Author

That works for me. Given the release timing, I think this is the right approach.

I was likely over-focusing on 1:1 Mermaid SVG parity and didn't pay enough attention to edge-case robustness. I'll do a quick audit of upstream merman for similar scenarios and follow up in a separate thread if I find anything.

@zed-zippy

zed-zippy Bot commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

🍒💥 Cherry-pick did not succeed
https://github.com/zed-industries/zed/actions/runs/26887234911

pull Bot pushed a commit to kevinru2023/zed that referenced this pull request Jun 3, 2026
I was a silly goose didn't notice my `git push` failed, so merged zed-industries#57967
without a critical commit, and some follow-ups.

This PR just cherry-picks those commits.

Release Notes:

- N/A or Added/Fixed/Improved ...
This was referenced Jun 3, 2026
smitbarmase pushed a commit that referenced this pull request Jun 3, 2026
Cherry-picks 2 PRs - originally meant to be 1 PR, but my local git state
was messed up, causing a `git push` to fail and I didn't notice:
- #57967
- #58419

Self-Review Checklist:

- [ ] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [ ] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [ ] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- N/A or Added/Fixed/Improved ...

---------

Co-authored-by: Latias94 <superfrankie621@gmail.com>
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request Jun 8, 2026
Following up on zed-industries#57644 by @cameron1024, this PR updates `merman` to
v0.6.

With merman 0.6's new raster-safe SVG pipeline, Zed can move generic
`usvg`/`resvg` cleanup passes out of this crate and rely on merman for
them instead.

**What's moved to merman:**
- `foreignObject` fallback text generation
- Unsupported CSS cleanup
- Invalid SVG attribute cleanup

**What's kept in Zed:**
- Theme CSS injection and accent color assignment
- Zed-specific fallback overlay handling

**Integration note:**
In merman v0.6, fallback overlay groups are marked with
`data-merman-foreignobject="fallback"` and preserve source classes like
`node` or `section-*`, so host CSS can still style fallback text. This
PR updates Zed's accent tracker to check for this marker, ensuring
fallback overlays are not treated as real layout nodes.

I also added a render-stage test for the new contract: the SVG output
from `render_mermaid` is already raster-safe before Zed-specific
post-processing runs.

---

### Self-Review Checklist:
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

### Release Notes:
- Improved rendering of Mermaid diagrams in Markdown previews.

### Tests:
- `cargo +1.95 fmt --check -p mermaid_render`
- `cargo +1.95 test -p mermaid_render`
- `cargo +1.95 clippy -p mermaid_render --all-targets -- -D warnings`
- `git diff --check HEAD~1..HEAD`

---------

Co-authored-by: cameron <cameron.studdstreet@gmail.com>
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request Jun 8, 2026
I was a silly goose didn't notice my `git push` failed, so merged zed-industries#57967
without a critical commit, and some follow-ups.

This PR just cherry-picks those commits.

Release Notes:

- N/A or Added/Fixed/Improved ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:preview/mermaid Feedback for Zed's Mermaid diagram support cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants