Render Mermaid fences inside callouts/quotes (follow-up from #22) #36

Closed
opened 2026-10-21 00:18:58 +02:00 by claude · 2 comments
Collaborator

This is a follow-up that #22 promised and never filed (the note on #22 said: "Mermaid fences inside callouts are still sent as code … I'll file that once !23 lands.").

Problem: a Mermaid diagram inside a > callout or quote reaches the tablet as a code block, not as a rendered diagram. On main, mermaidBlocks() in src/ink/mermaidtheme.ts:96 only matches top-level fences (/^\s*(```|~~~)\s*mermaid\b/). It doesn't strip > prefixes, so fences nested via !23's nestedQuotes path are never found.

Repro: a note containing

> [!note]
> ```mermaid
> flowchart LR
>   a --> b
> ```

→ send → the tablet shows the source as code.

Still to decide: whether the fix belongs in mermaidBlocks() (strip quote depth when scanning) or in the nested-quote rendering from !23, which would hand inner blocks to the same Mermaid path the top level uses.

Found while reviewing closed issues on #14.

This is a follow-up that #22 promised and never filed (the note on #22 said: *"Mermaid fences inside callouts are still sent as code … I'll file that once !23 lands."*). **Problem:** a Mermaid diagram inside a `>` callout or quote reaches the tablet as a code block, not as a rendered diagram. On `main`, `mermaidBlocks()` in `src/ink/mermaidtheme.ts:96` only matches top-level fences (`/^\s*(```|~~~)\s*mermaid\b/`). It doesn't strip `>` prefixes, so fences nested via !23's `nestedQuotes` path are never found. **Repro:** a note containing ``` > [!note] > ```mermaid > flowchart LR > a --> b > ``` ``` → send → the tablet shows the source as code. **Still to decide:** whether the fix belongs in `mermaidBlocks()` (strip quote depth when scanning) or in the nested-quote rendering from !23, which would hand inner blocks to the same Mermaid path the top level uses. Found while reviewing closed issues on #14.
Author
Collaborator

✅ Agent run completed

2m27s · 26 turns · $0.64 · pushed agent/mermaid-in-quotes · session saved — new comments resume this run

✅ **Agent run completed** _2m27s · 26 turns · $0.64 · pushed `agent/mermaid-in-quotes` · session saved — new comments resume this run_
Author
Collaborator

What I found

  • Reproduced on main @ 67092a6. For the preprocessed callout > **Note**\n> ```mermaid …, parseBlocks(…, { nestedQuotes: true }) already produces a nested code block (lang: "mermaid", lines ["flowchart LR", " a --> b"]). This holds at depth 1 and depth 2. But mermaidBlocks() (src/ink/mermaidtheme.ts:96) returns [], so noteDrawings() (src/main.ts:1703) never renders the diagram.
  • Decision: fix it in mermaidBlocks(). The rendering side already works for nested blocks: withImageBlocks() (src/ink/inkrender.ts:136-148) recurses into quote.blocks since !23, and swaps any code block whose diagramKey is in drawings. Mermaid rendering needs the DOM, so it can't move into the pure parse/render pipeline anyway.
  • The fix: strip quote levels with the parser's own ^\s*>\s? rule, removing exactly the opening fence's depth from each following line. Stop at the closing fence or where the quote ends. The source then hashes to the same diagramKey the parser's block does.

Created

  • !37: fix(ink): render Mermaid fences inside callouts/quotes (Closes #36). The description has the exact change, 4 tests, and a red gate.

Follow-ups

  • None. Out of scope for !37: Mermaid fences inside list items, and the existing case of a ```mermaid line inside another code fence.
## What I found - **Reproduced on `main` @ 67092a6.** For the preprocessed callout `> **Note**\n> ```mermaid …`, `parseBlocks(…, { nestedQuotes: true })` already produces a nested `code` block (`lang: "mermaid"`, lines `["flowchart LR", " a --> b"]`). This holds at depth 1 and depth 2. But `mermaidBlocks()` (`src/ink/mermaidtheme.ts:96`) returns `[]`, so `noteDrawings()` (`src/main.ts:1703`) never renders the diagram. - **Decision: fix it in `mermaidBlocks()`.** The rendering side already works for nested blocks: `withImageBlocks()` (`src/ink/inkrender.ts:136-148`) recurses into `quote.blocks` since !23, and swaps any code block whose `diagramKey` is in `drawings`. Mermaid rendering needs the DOM, so it can't move into the pure parse/render pipeline anyway. - **The fix:** strip quote levels with the parser's own `^\s*>\s?` rule, removing exactly the opening fence's depth from each following line. Stop at the closing fence or where the quote ends. The source then hashes to the same `diagramKey` the parser's block does. ## Created - !37: `fix(ink): render Mermaid fences inside callouts/quotes` (Closes #36). The description has the exact change, 4 tests, and a red gate. ## Follow-ups - None. Out of scope for !37: Mermaid fences inside list items, and the existing case of a ```` ```mermaid ```` line inside another code fence.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
daniel/obsidian-remarkable-round-trip#36
No description provided.