fix(ink): render Mermaid fences inside callouts/quotes #37
No reviewers
Labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
daniel/obsidian-remarkable-round-trip!37
Loading…
Reference in a new issue
No description provided.
Delete branch "agent/mermaid-in-quotes"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #36
What to change and where
One function:
mermaidBlocks()insrc/ink/mermaidtheme.ts:96. It needs to find Mermaid fences inside>quotes and callouts, at any depth. It must return each diagram's source exactly asparseBlocks(..., { nestedQuotes: true })puts it in the nestedcodeblock'slines, so thatdiagramKey(source)matches.Suggested shape:
^\s*>\s?, applied repeatedly (seequoteInnerinsrc/convert/mdblocks.ts:166, whichparseBlockscalls recursively once per level). Use it to get the opening line's quote depthdand its inner text, then test the existing/^\s*(```|~~~)\s*mermaid\b/against that inner text.dlevels:/^\s*(```|~~~)/on the inner text). The outeri++skips that line, as it does today.dquote markers, because the quote ended (e.g. a blank or unquoted line). That is where the parser's quote run ends, so an unclosed quoted fence ends there too. Do not consume that line: backiup one so the outer loop still sees it, since it could open another diagram.dlevels stripped. Do not strip more: a diagram line that itself starts with>keeps it, just as in the parser.d = 0) must behave exactly as today.Why
Reproduced on
main@67092a6. The input is the preprocessed callout"> **Note**\n> ```mermaid\n> flowchart LR\n> a --> b\n> ```\n"(flattenCalloutshas already turned> [!note]into> **Note**):parseBlocks(md, { html: true, quotePictures: true, nestedQuotes: true })→ quote →blockscontains{ type: "code", lang: "mermaid", lines: ["flowchart LR", " a --> b"] }, keymermaid:76715218. The same happens at depth 2 (> outer\n> > ```mermaid …).mermaidBlocks(md)→[].So
main.tsnoteDrawings()(src/main.ts:1703) never renders the diagram anddrawingshas no entry for it. The renderer is already wired up for nested blocks:withImageBlocks()insrc/ink/inkrender.ts:136-148recurses intoquote.blocks(added in !23 for pictures) and swaps anycodeblock whosediagramKeyis indrawingsfor aninkimage. Collecting the source is the only missing piece.Constraints and decisions
mermaidBlocks(), not in the nested-quote rendering. Rendering a Mermaid diagram needs the DOM and an asyncmermaid.renderinmain.ts. The pureparseBlocks→renderInkpipeline can't do that, and it already handles nested code → drawing swaps. KeepparseBlocks,withImageBlocksanddiagramKeyunchanged.nestedQuotesis off), so they never produce a nested code block, and an extra recorded drawing entry is harmless.inkDiagrams !== "handwritten", nothing changes:noteDrawingsreturns early.Scope boundary
Not part of this MR: fences inside list items, and
mermaidBlocksmis-detecting a```mermaidline that sits inside another code fence. That second limitation already exists at top level and is unchanged here. No changes tomdblocks.ts.Tests (add to
src/__tests__/ink-drawing.test.ts,describe("Mermaid sources"))"> **Note**\n> ```mermaid\n" + SOURCES.flowchart (each line prefixed "> ") + "\n> ```":mermaidBlocksreturns[SOURCES.flowchart], and itsdiagramKeyequals the key of the nestedcodeblock found by walkingparseBlocks(md, { nestedQuotes: true })quote blocks.> >), plus a line whose content keeps indentation (> a --> b→" a --> b").withImageBlocks(parseBlocks(md, { nestedQuotes: true }), undefined, { [diagramKey(src)]: FLOWCHART })gives a quote whoseblockscontainsinkimageand nocode.Validation contract
The repo has no flake.nix, so run Node directly:
npm cifirst.mermaidBlocksreturns[]instead of[SOURCES.flowchart].npx vitest run src/__tests__/ink-drawing.test.ts→ all pass, including the existing "finds fenced diagrams exactly as the block parser sees them".npx vitest run→ whole suite passes.npx tsc -noEmit -skipLibCheck→ exit 0.npx eslint src/ink/mermaidtheme.ts→ clean.🤖 Generated with Claude Code
✅ Agent run completed
2m17s · 19 turns · $0.46 · pushed
agent/mermaid-in-quotes· session saved — new comments resume this runclaude referenced this pull request2026-10-21 00:28:50 +02:00
claude referenced this pull request2026-10-21 00:28:50 +02:00
What changed
mermaidBlocks()(src/ink/mermaidtheme.ts) now finds Mermaid fences inside>quotes and callouts at any depth. It reads the opening line's quote depthdwith the parser's^\s*>\s?rule, then strips exactlydlevels from each later line. The source ends at a closing fence, or where the quote ends (fewer thandmarkers). In the second case that line is handed back to the outer loop, so it can still open the next diagram. Top-level fences behave as before. The doc comment is updated.describe("Mermaid sources")insrc/__tests__/ink-drawing.test.ts: callout at depth 1; depth 2, keeping a line's indentation; an unclosed quoted fence followed by a top-level fence; and thewithImageBlocksswap toinkimage. No changes tomdblocks.ts,withImageBlocksordiagramKey.Verify
Red gate: the 4 new tests fail on the old code. Now:
ink-drawing.test.ts14/14 pass; fullvitest run782 passed, 0 failed, 1 skipped;tsc -noEmit -skipLibCheckexit 0; eslint clean. No CI pipeline has run for heade188a35yet; the only recent run is an older one onmain.Follow-ups
None. Out of scope, as the hand-off said: fences inside list items, and the existing mis-detection of a
```mermaidline inside another code fence.