feat: render dot and graphviz fences as ascii diagrams - #48
Merged
Conversation
Startup benchmark (
|
| build | mean | ratio | verdict |
|---|---|---|---|
| baseline (main@5b74c1e) | 722.1ms ± 31.2ms | — | |
| PR | 696.7ms ± 13.0ms | 0.96× | ✅ ok |
Thresholds: warn ≥ 1.1×, fail ≥ 1.25×. Baseline built from main.
Translate a subset of DOT into a mermaid flowchart and reuse the existing ascii renderer. Constructs with no flowchart equivalent (records, ports, HTML labels) fall through to a framed code block.
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.
viewmdnow rendersdotandgraphvizfenced code blocks as ASCII diagrams. A new translator converts a subset of DOT into a Mermaid flowchart, which the existing ASCII renderer paints.DOT diagrams are common in READMEs and skill files, and until now they rendered as raw source inside a framed code block. Mermaid fences already rendered as ASCII, so DOT was the remaining gap.
Key Changes
dotToMermaidparses DOT and emits a Mermaid flowchart. It is a hand written lexer and parser, so no dependency is added.UnsupportedDotError. These are record shapes, ports, and HTML labels.replaceDotBlocksrendersdotandgraphvizfences through the Mermaid ASCII renderer.replaceMermaidBlocksso both fence types behave the same.<br/>literally. Undirected edges become arrows, because a flowchart has no undirected edge.test/graph-digraph.mdexercises each supported construct plus the fallback cases.Overall Flow
flowchart TD A[markdown source] --> B[replaceMermaidBlocks] B --> C[replaceDotBlocks] C --> D{dot or graphviz fence?} D -->|no| G[buildTree] D -->|yes| E[dotToMermaid] E -->|translated| F[renderMermaidAscii] E -->|UnsupportedDotError| H[leave fence unchanged] F -->|rendered| I[mermaidascii fence] F -->|throws| H I --> G H --> GThe preprocess stage previously ran only the Mermaid pass. DOT now runs as a second pass over the same output.
References / Links