markdown: Support triple-tilde Mermaid fences - #62257
Conversation
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: 김서규.
|
|
Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: 김서규.
|
5ce784d to
b614d81
Compare
|
We require contributors to sign our Contributor License Agreement, and we don't have @KimSeogyu on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
smitbarmase
left a comment
There was a problem hiding this comment.
Thanks! I pushed two commits to align the implementation with CommonMark:
- Code fences can contain three or more characters. With a valid block like
~~~~mermaid ... ~~~~, stripping exactly three characters left a trailing~in the Mermaid source. We now strip the complete closing fence. - A closing fence must use the same character as the opener and be at least as long. For example,
```mermaid ... ~~~is not closed, so we no longer mark it as such.
I added regression tests for both cases.
Thanks again.
# Objective Zed's Markdown parser accepts tilde-fenced code blocks, but Mermaid extraction only strips backtick fences. As a result, a block like this is parsed as Mermaid while the fence itself is still passed to the renderer: ```markdown ~~~mermaid graph TD; ~~~ ``` ## Solution Teach the Markdown code-block helpers to recognize triple-tilde fences alongside triple-backtick fences. The change stays in the existing parsing path, so Mermaid rendering does not need a separate special case. A regression test covers extraction from a tilde-fenced Mermaid block. ## Testing - `cargo fmt --all -- --check` - `cargo test -p markdown` (138 tests) - `./script/clippy -p markdown` - `cargo build -p zed` - Opened a `~~~mermaid` block in the built Zed Dev app on macOS and verified that Markdown Preview renders the diagram ## 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 adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable --- Release Notes: - Fixed Mermaid diagrams in Markdown previews when they use triple-tilde fences. --------- Co-authored-by: Smit Barmase <heysmitbarmase@gmail.com>
Objective
Zed's Markdown parser accepts tilde-fenced code blocks, but Mermaid extraction only strips backtick fences. As a result, a block like this is parsed as Mermaid while the fence itself is still passed to the renderer:
Solution
Teach the Markdown code-block helpers to recognize triple-tilde fences alongside triple-backtick fences.
The change stays in the existing parsing path, so Mermaid rendering does not need a separate special case. A regression test covers extraction from a tilde-fenced Mermaid block.
Testing
cargo fmt --all -- --checkcargo test -p markdown(138 tests)./script/clippy -p markdowncargo build -p zed~~~mermaidblock in the built Zed Dev app on macOS and verified that Markdown Preview renders the diagramSelf-Review Checklist:
Release Notes: