mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-20 23:25:43 +01:00
Answer stability round 2: a link slot keeps a linked image linked, so the link-in-link refusal holds
This commit is contained in:
@@ -299,7 +299,7 @@ function pushNode(scan: Scan, node: AdfNode): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function assemble(scan: Scan): Result<Scanned> {
|
function assemble(scan: Scan): Result<Scanned> {
|
||||||
const nodes = resolveNodes(scan.inLink ? scan.pieces : scan.pieces.map(linkedAlt), scan, true)
|
const nodes = resolveNodes(scan.pieces.map((piece) => (scan.inLink && piece.kind === 'image' && piece.link === undefined ? piece : linkedAlt(piece))), scan, true)
|
||||||
if (!nodes.ok) return nodes
|
if (!nodes.ok) return nodes
|
||||||
const [only] = scan.pieces
|
const [only] = scan.pieces
|
||||||
return success(scan.pieces.length === 1 && only?.kind === 'image' ? { image: mediaSingle(only), nodes: nodes.value } : { nodes: nodes.value })
|
return success(scan.pieces.length === 1 && only?.kind === 'image' ? { image: mediaSingle(only), nodes: nodes.value } : { nodes: nodes.value })
|
||||||
@@ -549,7 +549,7 @@ function mergeReadText(items: readonly Inline[]): Inline[] {
|
|||||||
return merged
|
return merged
|
||||||
}
|
}
|
||||||
|
|
||||||
// The image arm is an image inside an image's description or a link's text, which reads as its plain alt text: `assemble` links every other.
|
// The image arm is an image inside an image's description or a link's text, which reads as its plain alt text.
|
||||||
// A highlight delimiter holds an empty text node until it pairs, so the emphasis around it marks it.
|
// A highlight delimiter holds an empty text node until it pairs, so the emphasis around it marks it.
|
||||||
function pieceNodes(piece: Piece): Inline[] {
|
function pieceNodes(piece: Piece): Inline[] {
|
||||||
switch (piece.kind) {
|
switch (piece.kind) {
|
||||||
|
|||||||
@@ -985,6 +985,7 @@ test('reads a lone image as the media the flavour spells for it', () => {
|
|||||||
assert.deepEqual(content(losslessMarkdownToAdf('\n')), [image('/u')])
|
assert.deepEqual(content(losslessMarkdownToAdf('\n')), [image('/u')])
|
||||||
assert.deepEqual(content(losslessMarkdownToAdf('\n')), [image('/u', 'a')])
|
assert.deepEqual(content(losslessMarkdownToAdf('\n')), [image('/u', 'a')])
|
||||||
assert.deepEqual(content(losslessMarkdownToAdf('- \n')), [bulletList(item(image('/u', 'a')))])
|
assert.deepEqual(content(losslessMarkdownToAdf('- \n')), [bulletList(item(image('/u', 'a')))])
|
||||||
|
assert.deepEqual(content(losslessMarkdownToAdf('> \n')), [quote(image('/u', 'a'))])
|
||||||
})
|
})
|
||||||
|
|
||||||
test('flattens the description of a lone image to the plain text alt holds', () => {
|
test('flattens the description of a lone image to the plain text alt holds', () => {
|
||||||
@@ -1040,6 +1041,7 @@ test('reads an image inside a link not alone in its paragraph as plain alt text
|
|||||||
const unspellable = { attrs: { href: 'a\nb' }, type: 'link' }
|
const unspellable = { attrs: { href: 'a\nb' }, type: 'link' }
|
||||||
assert.deepEqual(firstContent('!adf:link[b ]{href="a\\nb"}\n'), [marked('b a', unspellable)])
|
assert.deepEqual(firstContent('!adf:link[b ]{href="a\\nb"}\n'), [marked('b a', unspellable)])
|
||||||
assert.deepEqual(firstContent('!adf:link[!adf:underline[]]{href="a\\nb"}\n'), [marked('a', unspellable, { type: 'underline' })])
|
assert.deepEqual(firstContent('!adf:link[!adf:underline[]]{href="a\\nb"}\n'), [marked('a', unspellable, { type: 'underline' })])
|
||||||
|
assert.equal(content(losslessMarkdownToAdf('!adf:link[x [](/v)]{href="a\\nb"}\n')), 'unsupported-node-shape: no link wraps a link: the [content] this one marks already holds one')
|
||||||
})
|
})
|
||||||
|
|
||||||
test('carries the mark a spelling nested inside its own kind names once', () => {
|
test('carries the mark a spelling nested inside its own kind names once', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user