feat: add box-drawing character input for treeView diagrams#7721
Conversation
- boxDrawingPreprocessor.ts: converts box-drawing chars to indent format - parser.ts: integrate preprocessor with error line remapping - 41 unit tests + 4 AST equivalence integration tests - 2 demo sections in treeView.html
- Tabs are now expanded to spaces instead of being rejected - Added Box-Drawing Input section to treeView documentation - Created changeset for changelog entry
🦋 Changeset detectedLatest commit: 4f05e82 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for mermaid-js ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
@mermaid-js/examples
mermaid
@mermaid-js/layout-elk
@mermaid-js/layout-tidy-tree
@mermaid-js/mermaid-zenuml
@mermaid-js/parser
@mermaid-js/tiny
commit: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7721 +/- ##
==========================================
- Coverage 3.30% 3.29% -0.01%
==========================================
Files 560 562 +2
Lines 58344 58491 +147
Branches 873 874 +1
==========================================
+ Hits 1928 1929 +1
- Misses 56416 56562 +146
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
The latest updates on your projects. Learn more about Argos notifications ↗︎
|
ashishjain0512
left a comment
There was a problem hiding this comment.
[sisyphus-bot]
Lovely PR — paste-and-render of tree-style output is exactly the kind of usability win that scales, and the way you've built it (preprocessor outside the Langium grammar) keeps the risk surface as small as it can be. Thanks especially for the screenshot-rich description and the file-by-file breakdown.
What's working well
- 🎉 [praise] Architecture is exactly right. Preprocessing box-drawing input into the existing indent format, instead of teaching the Langium grammar a second syntax, isolates the entire change to one file with no grammar regen, no risk to the indent-format parse path, and a single integration point in
parser.ts:51-62. This is the kind of change other diagram types should crib from when they want to add alternate input forms. - 🎉 [praise] The AST-equivalence test pattern in
parser.spec.ts:932is gold. Asserting that box-drawing input produces the samecollectNodessnapshot as the equivalent indent input is the cleanest possible proof of correctness — and you cover flat lists, nested directories, annotations, and 4-level nesting with both formats. Beautiful. - 🎉 [praise] Comprehensive preprocessor coverage. 42-ish unit tests in
boxDrawingPreprocessor.spec.tscovering format detection, depth inference, heavy Unicode variants (┣━━/┗━━/┃),:::class/icon()/##annotation passthrough, comments, blank lines, accessibility metadata, decoration-only lines, line-mapping, error cases, and realtreecommand output. Plenty of tree-shaped corner cases got thought through. - 🎉 [praise] Thoughtful UX details. Auto-detection (no flag/keyword variant required), parse-error line remapping back to the user's original input, tab→4-space normalization, the helpful error message on mixed format ("In box-drawing format, use ├── or └── prefixes for indented nodes.") — these are all the small things that make the difference between "works" and "feels good to use."
- 🎉 [praise] Both source and generated docs updated.
packages/mermaid/src/docs/syntax/treeView.mdand the generateddocs/syntax/treeView.mdare in sync, demo HTML atdemos/treeView.html:142-181adds two examples, changeset is present with the rightminorbump andfeat:prefix. - 🎉 [praise] Clean changeset narrative. Describing the preprocessor, error remapping, and test count up front makes the release notes actually useful.
Nits
- 🟢 [nit] Silent drop of unrecognized box-character lines. In
boxDrawingPreprocessor.ts:860-862, once box-drawing format is detected, any line that contains box-drawing characters but no branch character (├└┣┗) hits thecontinuebranch and is silently dropped. The intent is clearly "skip vertical-bar decoration lines like│ │" — but it would also drop a user's top-level node name that happens to contain a horizontal line character (e.g.,"Section ─ A.txt"). This is an exotic case, but silent drops are a particularly nasty failure mode because the user has no way to know their content was lost. Worth considering: onlycontinueif the line consists entirely of box characters and whitespace (i.e., the existingDECORATION_ONLYtest, but extended to include─/━), and otherwise fall through to passthrough or a clearer error. - 🟢 [nit] Small typo in the docs:
packages/mermaid/src/docs/syntax/treeView.md:32has "you can turn those into diagrams into Mermaid diagrams" — the second "into" is duplicated. The same line appears in the generateddocs/syntax/treeView.mdso a docs rebuild after the source fix will pick it up automatically. - 🟢 [nit] Test-count drift between changeset and PR description. The changeset says "Includes 41 unit tests and 4 AST equivalence integration tests"; the PR description's file table says "42 unit tests." Whichever is correct — they should match.
Suggestions
- 💡 [suggestion] Inconsistent-indent guard.
inferSegmentWidthpicks the column of the first indented branch char and uses it as the divisor for every line. If a user happens to mix 2-space and 4-space indentation in the same input (more likely than you'd think with tools likeeza --treeandlsd --treethat pick different defaults), depth inference will round to the wrong level for the off-rhythm rows. Worth considering a follow-up that either (a) checks each branch column is actually a multiple ofsegmentWidthand surfaces a friendly error, or (b) tracks the most-common gap between consecutive indented rows. Definitely out of scope for this PR — just a thought for a follow-up if real-world inputs surface it.
Security
No XSS or injection concerns. The preprocessor is purely text-in / text-out: splits on \n, regex-tests for box characters, builds an indent string with INDENT_UNIT.repeat(depth), and hands the result to the existing Langium parser. Final output continues to flow through the established sanitizeText() boundary in populate(). No new DOM sinks, no HTML/SVG concatenation.
This is in great shape — feel free to land it whenever you're happy. The nits are all small enough to fix in this PR or follow up in a separate one. Thanks again for picking this up! 🙌
|
@ashishjain0512 could you take a look at the argos check please? I can't see anything in it that blocks this from being merged. |
📑 Summary
Adds an alternative input syntax for
treeView-betadiagrams using box-drawing characters (├──,└──,│). This is a follow-up to #7527 and addresses the original request in #7516.Most file-tree diagrams people encounter already use box-drawing characters, so this allows them to be pasted directly into Mermaid with minimal effort:
Simple Box-drawing:
Box-drawing with annotations:
📏 Design Decisions
boxDrawingPreprocessor.tsconverts box-drawing input to indent-based format before Langium parsing — this keeps the Langium grammar unchanged and avoids parser complexity.├──,└──,│) and heavy (┣━━,┗━━,┃) Unicode box-drawing characters are supported.📋 Tasks
MERMAID_RELEASE_VERSIONis used for all new features.pnpm changesetand following the prompts.Files Changed
boxDrawingPreprocessor.tsboxDrawingPreprocessor.spec.tsparser.tsparser.spec.tsdemos/treeView.htmlsrc/docs/syntax/treeView.md.changeset/add-treeview-box-drawing-input.md