From 3349b81b5a0eb3f7e577d07cbbb4c433a9de4fbd Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Mon, 31 Aug 2026 22:33:21 +0200 Subject: [PATCH] Spell the alt rule in the flavour both directions read --- spec/flavour.md | 3 ++- src/markdown/parse/inline-content.ts | 15 ++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/spec/flavour.md b/spec/flavour.md index 5bed709..7a93968 100644 --- a/spec/flavour.md +++ b/spec/flavour.md @@ -245,7 +245,8 @@ The moon, at night. **The CommonMark image.** A paragraph whose entire inline content is one image `![alt](url)` is a `mediaSingle` with attrs exactly `{"layout":"center"}` holding an `external` `media` — `url` -from the destination, `alt` the description's plain-text content when non-empty. `adfToMarkdown` +from the destination, `alt` the description's plain-text content when non-empty — a link or image +inside it contributing its own text, and a break of either kind a space. `adfToMarkdown` emits the image form for exactly that shape — those attrs and no others, no marks on either node, no caption, and a `media` carrying nothing beyond `alt`, `type` and `url` — and only where CommonMark spells the pair: a destination or a description the image form cannot hold, an empty diff --git a/src/markdown/parse/inline-content.ts b/src/markdown/parse/inline-content.ts index dc00c5c..c329909 100644 --- a/src/markdown/parse/inline-content.ts +++ b/src/markdown/parse/inline-content.ts @@ -250,7 +250,6 @@ function closeImage(scan: Scan, at: number, inner: readonly Piece[], definition: return success(null) } -// spec/flavour.md: the description's plain-text content, where a break of either kind reads as a space. function imageAlt(inner: readonly Piece[]): string { return resolveNodes(inner) .map((node) => (node.type === 'hardBreak' ? ' ' : (node.text ?? ''))) @@ -268,10 +267,16 @@ function resolveNodes(pieces: readonly Piece[]): AdfNode[] { // Only `imageAlt` reaches the image arm: everywhere else an image amid other content is refused first. function pieceNodes(piece: Piece): AdfNode[] { - if (piece.kind === 'nodes') return piece.nodes - if (piece.kind === 'open') return bracketNodes(piece) - if (piece.kind === 'image') return piece.alt === '' ? [] : [{ text: piece.alt, type: 'text' }] - return [] + switch (piece.kind) { + case 'image': + return piece.alt === '' ? [] : [{ text: piece.alt, type: 'text' }] + case 'nodes': + return piece.nodes + case 'open': + return bracketNodes(piece) + case 'run': + return [] + } } function delimiterRuns(pieces: readonly Piece[]): Run[] {