From 8d9d1ecb5bddd30d2491f0043352b165b3fbac58 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Wed, 30 Sep 2026 17:01:15 +0200 Subject: [PATCH] 41 - review: title text keeps its own spelling, only a node without text reads as the reduction does --- README.md | 2 +- src/markdown/parse/markdown-to-adf.ts | 10 +++++++--- src/markdown/parse/plain-markdown-to-adf.test.ts | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 31eda5b..96df37b 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ read replaces mentions, attachments and macros with text. | ADF | Written | Read back | | --- | --- | --- | | `panel` | a GitHub alert, `> [!WARNING]`: info `NOTE`, note `IMPORTANT`, tip and success `TIP`, warning `WARNING`, error `CAUTION`, custom `NOTE` | `NOTE` info, `IMPORTANT` note, `TIP` tip, `WARNING` warning, `CAUTION` error, and Obsidian's: hint tip; success, check, done success; attention warning; danger, failure, fail, missing, bug, error error; any other word info — in any case; the rest of the marker's line is the first paragraph | -| `expand`, `nestedExpand` | Obsidian's folded callout, `> [!NOTE]- Title` | `-` or `+` after any word, the rest of the marker's line the title, a link as `text (target)`, one whose text is its target as its text; an expand inside an expand is a `nestedExpand` | +| `expand`, `nestedExpand` | Obsidian's folded callout, `> [!NOTE]- Title` | `-` or `+` after any word, the rest of the marker's line the title, a link as `text (target)`, one whose text is its target, `mailto:` aside, as its text; an expand inside an expand is a `nestedExpand` | | `taskList` | `- [x] Done`, `- [ ] Todo` | a bullet list whose every item is so marked, `[X]` too | | `backgroundColor` | `==text==` | `==text==` on one line, the text touching both delimiters, bounded outside by whitespace, punctuation or a line edge, or touching a Han, Hangul, Hiragana, Katakana, Thai, Lao, Khmer or Myanmar character on either side, in the editor's default highlight `#f8e6a0` | | `table` | a pipe table: the first row its header, a cell's blocks on one line, a span kept under its header by empty cells | — | diff --git a/src/markdown/parse/markdown-to-adf.ts b/src/markdown/parse/markdown-to-adf.ts index 5a85072..8ed8a6a 100644 --- a/src/markdown/parse/markdown-to-adf.ts +++ b/src/markdown/parse/markdown-to-adf.ts @@ -131,9 +131,13 @@ function quoteNode(blocks: readonly Block[], reading: Reading, path: ConvertErro const title = parseInlineContent(line, reading.definitions, path, 'paragraph', 'lossless') if (!title.ok) return title if (title.value.image !== undefined) return failure('unmappable-image', imageOnMarkerLine, path) - const leaves = inlineLeaves(title.value.nodes, 'paragraph', path, depth) - if (!leaves.ok) return leaves - const text = titleText(leaves.value) + const leaves: AdfNode[] = [] + for (const [index, node] of title.value.nodes.entries()) { + const held = node.text === undefined ? inlineLeaves([node], 'paragraph', [...path, 'content', index], depth) : success([node]) + if (!held.ok) return held + leaves.push(...held.value) + } + const text = titleText(leaves) const type = reading.inExpand ? 'nestedExpand' : 'expand' return filledNode(text === '' ? { type } : { attrs: { title: text }, type }, readMarked(paragraphsOf(led.position, rest), false, body, { ...reading, inExpand: true }, path, depth)) } diff --git a/src/markdown/parse/plain-markdown-to-adf.test.ts b/src/markdown/parse/plain-markdown-to-adf.test.ts index 4fb4b94..d38e883 100644 --- a/src/markdown/parse/plain-markdown-to-adf.test.ts +++ b/src/markdown/parse/plain-markdown-to-adf.test.ts @@ -122,7 +122,8 @@ test('reads a folded callout to an expand titled by the rest of its marker line, assert.deepEqual(read('> [!NOTE]- Two\\\n> lines\n'), [node('expand', { title: 'Two' }, said('lines'))]) assert.deepEqual(read('> [!faq]- See [x](http://y)\n'), normal(node('expand', { title: 'See x (http://y)' }, paragraph()))) assert.deepEqual(read('> [!faq]- [a **b**](u "t")[c](u) and [d](v)\n'), normal(node('expand', { title: 'a bc (u) and d (v)' }, paragraph()))) - assert.deepEqual(read('> [!faq]- or \n'), normal(node('expand', { title: 'http://y or a@b.c' }, paragraph()))) + assert.deepEqual(read('> [!faq]- or or \n'), normal(node('expand', { title: 'http://y or a@b.c or http://a\\b' }, paragraph()))) + assert.deepEqual(read('> [!faq]- [a b](u)\n'), normal(node('expand', { title: 'a\nb (u)' }, paragraph()))) assert.deepEqual(read('> [!faq]- [!adf:mention[@M]{id=5}](u) !adf:inlineCard{url="http://y"}\n'), normal(node('expand', { title: '@M (u) http://y' }, paragraph()))) assert.deepEqual(read('> [!NOTE]- Set ==x== here\n'), normal(node('expand', { title: 'Set ==x== here' }, paragraph()))) assert.deepEqual(read('> [!NOTE]-\n>\n> Line.\n'), [bare('expand', said('Line.'))])