Skip to content

tui: Mermaid renderer displays <b>/<strong> tags literally and ignores \n line breaks #66773

Backlog

Description

@danielfn

Description

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:

export function parseDiagramTextLines(value: string): DiagramTextLine[] {
  return value.split(/<br\s*\/?>/i).map((line) => {
    const runs: DiagramTextRun[] = []
    const source = line.trim()
    const tag = /<\/?(?:i|em)\s*>/gi

Plugins

None

OpenCode version

v2.1.2

Steps to reproduce

  1. Render a Mermaid flowchart in the TUI containing <b> / <strong> tags and \n line breaks in node labels:
```mermaid
flowchart TD
  A["<b>Service A</b>\nLine 2"] --> B["<strong>Service B</strong><br/>Line 2"]
```
  1. Observe that <b>Service A</b> and <strong>Service B</strong> are displayed with literal HTML tags and \n does not break the line.

Screenshot

N/A

Operating System

Linux (WSL2 - 6.18.33.2-microsoft-standard-WSL2)

Terminal

herdr

Activity

  1. added
    area/tui
    platform/wsl
    type/bug
    version/v2
    on Nov 27, 2026
  2. opencodejr commented on Nov 27, 2026

    @opencodejr
    Contributor

    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.

    Related: #63670 (another Mermaid construct the TUI renderer doesn't parse yet).

    https://anoma.ly/team/github-bot/media/394514df76331175764bc6f4397d32618da29638a9bcc0a581e5d4c8a2659078.mp4

    Screenshot

    Reproduction script (drive.ts)
    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.
    const reply = [
      "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")
    
    export default OpenCodeDriver.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.

  3. added
    status/repro-simulated
    on Nov 27, 2026
  4. argszero commented on Nov 27, 2026

    @argszero
    Contributor

    I'd like to work on this.

    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.

  5. Guembri01 commented on Nov 27, 2026

    @Guembri01

    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.

  6. argszero commented on Nov 28, 2026

    @argszero
    Contributor

    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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/tuiplatform/wslstatus/repro-simulatedtype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions