fix(preprocess): flatten nested callout heads to titled quotes #24

Merged
daniel merged 3 commits from agent/nested-callout-titles into main 2026-10-20 18:52:29 +02:00
Collaborator

Part of #22

Problem

flattenCallouts (src/preprocess/preprocess.ts:323) rewrites a callout head into a bold title line: > [!tip] Title → > **Title**, and a head with no title gets the capitalised type, e.g. > [!tip] → > **Tip**. It matches with CALLOUT_HEAD_RE = /^>\s*\[!([a-zA-Z-]+)\][+-]?\s*(.*)$/ (preprocess.ts:66), which only matches the outermost level. A callout nested in a callout or quote, > > [!tip] Inner (or >> [!tip]), therefore reaches the tablet as the literal text [!tip] Inner.

flattenCallouts also ignores code fences, so a fenced line starting with > [!note] (e.g. a markdown example) gets rewritten too.

What to change

  • In flattenCallouts, use a regex that keeps any quote prefix, e.g. /^(\s*(?:>\s?)+)\[!([a-zA-Z-]+)\][+-]?\s*(.*)$/, and output ${prefix}**${label}** with the same label rule as today: the title, else the capitalised type.
  • Track ``` / ~~~ fences in flattenCallouts the way remarksInPlace does (preprocess.ts:296) and leave fenced lines alone.
  • Leave CALLOUT_HEAD_RE and remarksInPlace unchanged. Remark callouts are always top-level, and their detection must not change.
  • Add a CHANGELOG-INK.md Unreleased bullet.

Constraints and decisions

  • Preprocessed markdown is what gets persisted as sent.markdown and replayed, so old sends are unaffected and this needs no replay flag. contentHash is over the preprocessed text, so a note with a nested callout is re-sent once on the next sync. That is intended.
  • This MR is independent of !23, which renders nested blocks (including > > **Inner**) inside quotes; the two can land in either order. Without !23, the nested title still shows as > **Inner** text inside the flat quote, which is already better than [!tip] Inner.

Validation contract

  • Red gate (fails on main today): in src/__tests__/preprocess.test.ts, next to "flattens callouts to titled blockquotes" (:196):
    • preprocess("> [!note] Outer\n> text\n> > [!tip] Inner\n> > more").markdown contains > > **Inner** and no [!tip].
    • > > [!warning] with no title → > > **Warning**.
    • A fenced block containing > [!note] X comes out unchanged.
  • The existing top-level callout tests stay green.
  • npm ci && npm test → green. npm run lint → exit 0.

🤖 Generated with Claude Code

Part of #22 ## Problem `flattenCallouts` (`src/preprocess/preprocess.ts:323`) rewrites a callout head into a bold title line: `> [!tip] Title` → `> **Title**`, and a head with no title gets the capitalised type, e.g. `> [!tip]` → `> **Tip**`. It matches with `CALLOUT_HEAD_RE = /^>\s*\[!([a-zA-Z-]+)\][+-]?\s*(.*)$/` (`preprocess.ts:66`), which only matches the **outermost** level. A callout nested in a callout or quote, `> > [!tip] Inner` (or `>> [!tip]`), therefore reaches the tablet as the literal text `[!tip] Inner`. `flattenCallouts` also ignores code fences, so a fenced line starting with `> [!note]` (e.g. a markdown example) gets rewritten too. ## What to change - In `flattenCallouts`, use a regex that keeps any quote prefix, e.g. `/^(\s*(?:>\s?)+)\[!([a-zA-Z-]+)\][+-]?\s*(.*)$/`, and output `${prefix}**${label}**` with the same label rule as today: the title, else the capitalised type. - Track ``` / ~~~ fences in `flattenCallouts` the way `remarksInPlace` does (`preprocess.ts:296`) and leave fenced lines alone. - **Leave `CALLOUT_HEAD_RE` and `remarksInPlace` unchanged.** Remark callouts are always top-level, and their detection must not change. - Add a CHANGELOG-INK.md *Unreleased* bullet. ## Constraints and decisions - Preprocessed markdown is what gets persisted as `sent.markdown` and replayed, so old sends are unaffected and this needs no replay flag. `contentHash` is over the preprocessed text, so a note with a nested callout is re-sent once on the next sync. That is intended. - This MR is independent of !23, which renders nested blocks (including `> > **Inner**`) inside quotes; the two can land in either order. Without !23, the nested title still shows as `> **Inner**` text inside the flat quote, which is already better than `[!tip] Inner`. ## Validation contract - **Red gate (fails on `main` today):** in `src/__tests__/preprocess.test.ts`, next to "flattens callouts to titled blockquotes" (`:196`): - `preprocess("> [!note] Outer\n> text\n> > [!tip] Inner\n> > more").markdown` contains `> > **Inner**` and no `[!tip]`. - `> > [!warning]` with no title → `> > **Warning**`. - A fenced block containing `> [!note] X` comes out unchanged. - The existing top-level callout tests stay green. - `npm ci && npm test` → green. `npm run lint` → exit 0. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude self-assigned this 2026-10-20 18:48:13 +02:00
Author
Collaborator

✅ Agent run completed

2m36s · 18 turns · $0.36 · pushed agent/nested-callout-titles · session saved — new comments resume this run

✅ **Agent run completed** _2m36s · 18 turns · $0.36 · pushed `agent/nested-callout-titles` · session saved — new comments resume this run_
Author
Collaborator

What changed

  • flattenCallouts now matches callout heads at any quote depth: > > [!tip] Inner / >> [!tip] Inner → > > **Inner**, and an untitled one gets the capitalised type (> > **Warning**). It also tracks ``` / ~~~ fences and leaves fenced lines alone. CALLOUT_HEAD_RE and remarksInPlace are unchanged; the new regex is a separate NESTED_CALLOUT_HEAD_RE.
  • Decision: I normalise the quote prefix to "> ".repeat(depth) (with any leading indent kept) rather than emitting it verbatim, so top-level output stays byte-identical to before (>[!tip] and > [!tip] still give > **Tip**) and >> [!tip] gives > > **Tip**.
  • Added a CHANGELOG-INK.md Unreleased bullet. Separately, npm run lint was already failing on main with 3 no-unsafe-* errors in src/__tests__/migrate.test.ts (from !19). I fixed it with an as typeof fixture cast in its own commit.

Verify

  • The 3 new tests in preprocess.test.ts failed with the old preprocess.ts and pass now.
  • npm test: 687/687 passing. npm run lint: exit 0.
  • No CI pipeline has run for head 879263d yet.

Follow-ups

None

## What changed - `flattenCallouts` now matches callout heads at any quote depth: `> > [!tip] Inner` / `>> [!tip] Inner` → `> > **Inner**`, and an untitled one gets the capitalised type (`> > **Warning**`). It also tracks ``` / ~~~ fences and leaves fenced lines alone. `CALLOUT_HEAD_RE` and `remarksInPlace` are unchanged; the new regex is a separate `NESTED_CALLOUT_HEAD_RE`. - **Decision:** I normalise the quote prefix to `"> ".repeat(depth)` (with any leading indent kept) rather than emitting it verbatim, so top-level output stays byte-identical to before (`>[!tip]` and `> [!tip]` still give `> **Tip**`) and `>> [!tip]` gives `> > **Tip**`. - Added a CHANGELOG-INK.md *Unreleased* bullet. Separately, `npm run lint` was already failing on `main` with 3 `no-unsafe-*` errors in `src/__tests__/migrate.test.ts` (from !19). I fixed it with an `as typeof fixture` cast in its own commit. ## Verify - The 3 new tests in `preprocess.test.ts` failed with the old `preprocess.ts` and pass now. - `npm test`: 687/687 passing. `npm run lint`: exit 0. - No CI pipeline has run for head `879263d` yet. ## Follow-ups None
daniel merged commit d202865971 into main 2026-10-20 18:52:29 +02:00
Sign in to join this conversation.
No reviewers
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!24
No description provided.