You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tui: Mermaid renderer displays <b>/<strong> tags literally and ignores \n line breaks #66773
In the TUI Mermaid renderer (packages/merman), HTML bold tags (<b>, <strong>) inside node labels are rendered literally instead of being formatted as bold (or stripped), and \n line breaks are not split into multiple lines.
Looking at packages/merman/src/core/text-lines.ts, parseDiagramTextLines only splits lines on <br>/<br/> and only parses <i>/<em> tags:
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
Thanks for the clear report and the code pointer. I reproduced this in the TUI on v2.1.2 by having a simulated model reply with your flowchart, and it still happens on the latest dev (2b8f912c).
Node A renders as <b>Service A</b>\nLine 2 on a single line, and node B as <strong>Service B</strong> above Line 2. In both, the tags show as literal text and nothing is bold. <br/> does split the line as expected. The recording and screenshot below show it, and the script below reproduces it.
The bold tags look like a gap in the label parsing you pointed to in packages/merman/src/core/text-lines.ts: it only splits on <br> and only handles <i>/<em>. I haven't confirmed that Mermaid itself treats a literal \n as a line break in quoted flowchart labels, so a maintainer may look at that part separately.
import{Effect,Stream}from"effect"import{Llm,OpenCodeDriver}from"opencode-drive"// Assistant reply containing a Mermaid flowchart with <b>/<strong> tags and a literal "\n" in a label.constreply=["Here is the diagram:","","```mermaid","flowchart TD",' A["<b>Service A</b>\\nLine 2"] --> B["<strong>Service B</strong><br/>Line 2"]',"```","","Done.",].join("\n")exportdefaultOpenCodeDriver.use({
...(process.env.OC_DEV ? {opencode: {dev: process.env.OC_DEV}} : {}),tui: {recording: true,viewport: {cols: 120,rows: 40}},},({ ui, llm })=>Effect.gen(function*(){yield*ui.screenshot("home")yield*llm.serve(()=>Stream.make(Llm.text(reply)))yield*ui.submit("Draw a diagram of service A and B")yield*ui.waitFor("Service B",{timeout: 30000}).pipe(Effect.catchTag("UiWaitTimeoutError",(e)=>Effect.log((e.frame?.lines??[]).map((l: any)=>JSON.stringify(l).slice(0,300)).join("\n"))))yield*Effect.sleep(1500)yield*ui.screenshot("mermaid")}),)
Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.
Confirmed on dev at 2b8f912c86 that the gap is where the report points: packages/merman/src/core/text-lines.ts:15 matches only i|em, so <b>/<strong> reach the grid as literal text.
The seam for it already exists. DiagramTextRun carries an italic flag (text-lines.ts:3), and flowchart/drawing.ts:66 maps that flag to TextAttributes.ITALIC. So bold is the same run flag plus TextAttributes.BOLD, not new style plumbing.
Scope I intend to take: the bold tags only, in both copies of the parser. There is a Rust twin of the same function at packages/cli-rs/crates/mermaid/src/core/text.rs:110 with the same italic-only regex and the same TextRun shape, so it gets the same treatment in the same change rather than being left describing the old behaviour.
parseDiagramTextLines gains a bold run state alongside the italic one, and the renderer applies both, so <b>/<strong> and nested cases like <i><b>x</b></i> stop leaking their tags.
The literal \n half I would rather not fold in. I could not establish from Mermaid's own grammar whether a quoted label's \n is meant to break the line, and the bot's comment says the same thing. That is a decision about what the diagram format means, so it belongs to a maintainer rather than to a fix where I would be guessing.
No open pull request touches packages/merman/src/core/text-lines.ts or packages/merman/src/flowchart/drawing.ts — the four open merman PRs (#60343, #60209, #63671, #61468) cover the parsers, the class diagrams and the state diagrams, so this should not collide with any of them.
The bold half of this is already fixed on dev (#66813), so I took the remaining one: the \n escape.
parseDiagramTextLines splits a label on <br> only, so A["<b>Service A</b>\nLine 2"] keeps a literal \n inside one line — and measureDiagramTextBox/diagramTextWidth use the same split, so the node is measured as one long line and drawn too wide. It now splits on <br>, the \n escape, and raw newlines; the bold/italic run parsing is unchanged and applies per line.
Test next to the existing <br> case: splitDiagramLines("Service A\\nLine 2<BR />Line 3") returns three lines, and parseDiagramTextLines("<b>Service A</b>\\n<strong>Line 2</strong>") returns two bold lines. With text-lines.ts reverted it fails (Expected -2 / Received +1); with the change it passes, and bun test in packages/merman is 511 pass with one unrelated pre-existing failure (StateDiagram > falls back before allocating an oversized horizontal canvas, fails with the change stashed too).
Branch mermaid-label-breaks at 3cf0326 is pushed with the body written. PR creation is returning 404 for this account again (it opened one PR earlier today, then closed), so it waits as a branch.
Yielding #66773 to you, @Guembri01 — my earlier note is superseded, go ahead with the \n escape.
Two file locations from the pass I had already made, in case they save you time:
TypeScript: packages/merman/src/core/text-lines.ts builds DiagramTextRun { text, italic }, splits only <br>, and recognises only <i> / <em>. packages/merman/src/flowchart/drawing.ts then applies TextAttributes.ITALIC when run.italic is set.
Rust twin: packages/cli-rs/crates/mermaid/src/core/text.rs has the same italic-only shape, so the two renderers may need the same \n handling to stay in step.
Activity
opencodejr commentedon Nov 27, 2026
Seen with a simulated model or a mock server, not a real provider; a maintainer should confirm.
Thanks for the clear report and the code pointer. I reproduced this in the TUI on v2.1.2 by having a simulated model reply with your flowchart, and it still happens on the latest
dev(2b8f912c).Node A renders as
<b>Service A</b>\nLine 2on a single line, and node B as<strong>Service B</strong>aboveLine 2. In both, the tags show as literal text and nothing is bold.<br/>does split the line as expected. The recording and screenshot below show it, and the script below reproduces it.The bold tags look like a gap in the label parsing you pointed to in
packages/merman/src/core/text-lines.ts: it only splits on<br>and only handles<i>/<em>. I haven't confirmed that Mermaid itself treats a literal\nas a line break in quoted flowchart labels, so a maintainer may look at that part separately.Related: #63670 (another Mermaid construct the TUI renderer doesn't parse yet).
https://anoma.ly/team/github-bot/media/394514df76331175764bc6f4397d32618da29638a9bcc0a581e5d4c8a2659078.mp4
Reproduction script (drive.ts)
Run it with opencode-drive:
opencode-drive run ./drive.ts. It drivesopencodefrom yourPATH; setOC_DEVto the path of an OpenCode checkout to run that from source instead.argszero commentedon Nov 27, 2026
I'd like to work on this.
Confirmed on
devat2b8f912c86that the gap is where the report points:packages/merman/src/core/text-lines.ts:15matches onlyi|em, so<b>/<strong>reach the grid as literal text.The seam for it already exists.
DiagramTextRuncarries anitalicflag (text-lines.ts:3), andflowchart/drawing.ts:66maps that flag toTextAttributes.ITALIC. So bold is the same run flag plusTextAttributes.BOLD, not new style plumbing.Scope I intend to take: the bold tags only, in both copies of the parser. There is a Rust twin of the same function at
packages/cli-rs/crates/mermaid/src/core/text.rs:110with the same italic-only regex and the sameTextRunshape, so it gets the same treatment in the same change rather than being left describing the old behaviour.parseDiagramTextLinesgains a bold run state alongside the italic one, and the renderer applies both, so<b>/<strong>and nested cases like<i><b>x</b></i>stop leaking their tags.The literal
\nhalf I would rather not fold in. I could not establish from Mermaid's own grammar whether a quoted label's\nis meant to break the line, and the bot's comment says the same thing. That is a decision about what the diagram format means, so it belongs to a maintainer rather than to a fix where I would be guessing.No open pull request touches
packages/merman/src/core/text-lines.tsorpackages/merman/src/flowchart/drawing.ts— the four open merman PRs (#60343, #60209, #63671, #61468) cover the parsers, the class diagrams and the state diagrams, so this should not collide with any of them.Guembri01 commentedon Nov 27, 2026
The bold half of this is already fixed on
dev(#66813), so I took the remaining one: the\nescape.parseDiagramTextLinessplits a label on<br>only, soA["<b>Service A</b>\nLine 2"]keeps a literal\ninside one line — andmeasureDiagramTextBox/diagramTextWidthuse the same split, so the node is measured as one long line and drawn too wide. It now splits on<br>, the\nescape, and raw newlines; the bold/italic run parsing is unchanged and applies per line.Test next to the existing
<br>case:splitDiagramLines("Service A\\nLine 2<BR />Line 3")returns three lines, andparseDiagramTextLines("<b>Service A</b>\\n<strong>Line 2</strong>")returns two bold lines. Withtext-lines.tsreverted it fails (Expected -2 / Received +1); with the change it passes, andbun testinpackages/mermanis 511 pass with one unrelated pre-existing failure (StateDiagram > falls back before allocating an oversized horizontal canvas, fails with the change stashed too).Branch
mermaid-label-breaksat3cf0326is pushed with the body written. PR creation is returning 404 for this account again (it opened one PR earlier today, then closed), so it waits as a branch.argszero commentedon Nov 28, 2026
Yielding #66773 to you, @Guembri01 — my earlier note is superseded, go ahead with the
\nescape.Two file locations from the pass I had already made, in case they save you time:
packages/merman/src/core/text-lines.tsbuildsDiagramTextRun { text, italic }, splits only<br>, and recognises only<i>/<em>.packages/merman/src/flowchart/drawing.tsthen appliesTextAttributes.ITALICwhenrun.italicis set.packages/cli-rs/crates/mermaid/src/core/text.rshas the same italic-only shape, so the two renderers may need the same\nhandling to stay in step.