Add grok-mermaid: Mermaid-to-Unicode box-art renderer#293
Merged
Conversation
Extracts the Mermaid-to-Unicode-box-drawing renderer from xai-org/grok-build (crates/codegen/xai-grok-markdown/src/mermaid.rs, Apache-2.0) and compiles it to WebAssembly for a browser playground. - grok-mermaid/: standalone Rust crate. src/mermaid.rs is the upstream file unmodified except two import lines, which now point at src/shim.rs, a small stand-in for the four ratatui types it uses (Style carries a CSS class name instead of terminal colors). src/lib.rs adds render_plain/render_html and a wasm-bindgen-free FFI. Includes the upstream Apache-2.0 LICENSE; all 148 upstream unit tests pass unchanged via cargo test. - grok-mermaid/build_wasm.sh: cargo build --target wasm32-unknown-unknown (plus optional wasm-opt) producing grok-mermaid.wasm (~190 KB). - grok-mermaid.html: playground with editable source, seven example diagrams (flowchart, subgraphs, sequence, state, class, ER, unsupported fallback), max-width control, copy-as-text and shareable URL fragment. - tests/test_grok_mermaid.py: Playwright coverage for initial render, example buttons, live editing and URL-fragment loading. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NHbXcjun9Rg1yn55N4P497
Contributor
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Demo: https://claude-mermaid-unicode-wasm.tools-b1q.pages.dev/grok-mermaid
Summary
This PR adds
grok-mermaid, an in-browser playground for rendering Mermaid diagram source as terminal-style Unicode box-drawing art. The implementation extracts and adapts the renderer from xai-org/grok-build, making it available as a standalone WebAssembly module with a web UI.Key Changes
New Rust library (
grok-mermaid/):src/mermaid.rs: Core renderer (copied from xai-org/grok-build under Apache-2.0)src/lib.rs: Safe Rust entry points (render_plain,render_html) and WebAssembly FFI surfacesrc/shim.rs: Minimal stand-ins for ratatui types (Style,Modifier,Span,Line) to avoid pulling in the full ratatui dependencyCargo.toml: Package configuration for wasm32 targetbuild_wasm.sh: Build script to compile to WebAssemblyWeb UI (
grok-mermaid.html):bfor border,nfor node text,efor edge,elfor edge label,tfor title,ifor italic)Testing (
tests/test_grok_mermaid.py):Build artifacts:
grok-mermaid.wasm: Compiled WebAssembly moduleLICENSE: Apache-2.0 license (matching source)README.md: Documentation on the origin and rebuild processConfiguration: Updated
.gitignoreto exclude Rust build outputImplementation Details
wasm_alloc,wasm_render_html,wasm_result_ptr) for browser integration, avoiding wasm-bindgen overhead<span>tags with semantic class names, allowing the page to apply custom theminghttps://claude.ai/code/session_01NHbXcjun9Rg1yn55N4P497