41 - plainMarkdownToAdf keeps a callout title's link targets; Goal 6, what happens is what the audience expects
This commit is contained in:
@@ -130,11 +130,31 @@ 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 text = title.value.nodes.map((node) => node.text ?? '').join('')
|
||||
const text = titleText(title.value.nodes)
|
||||
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))
|
||||
}
|
||||
|
||||
// docs/decisions.md, A callout title keeps its link targets.
|
||||
function titleText(nodes: readonly AdfNode[]): string {
|
||||
let text = ''
|
||||
let linked = ''
|
||||
for (const [index, node] of nodes.entries()) {
|
||||
const href = linkTarget(node)
|
||||
text += node.text ?? ''
|
||||
linked += href === undefined ? '' : node.text ?? ''
|
||||
if (href === undefined || linkTarget(nodes[index + 1]) === href) continue
|
||||
if (href !== linked && href !== `mailto:${linked}`) text += ` (${href})`
|
||||
linked = ''
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
function linkTarget(node: AdfNode | undefined): string | undefined {
|
||||
const href = node?.marks?.find((mark) => mark.type === 'link')?.attrs?.href
|
||||
return typeof href === 'string' ? href : undefined
|
||||
}
|
||||
|
||||
// Atlassian's schema requires a panel and an expand to hold a block.
|
||||
function filledNode(node: AdfNode, content: Result<AdfNode[]>): Result<AdfNode> {
|
||||
if (!content.ok) return content
|
||||
|
||||
@@ -120,6 +120,9 @@ test('reads a folded callout to an expand titled by the rest of its marker line,
|
||||
node('expand', { title: 'Why?' }, paragraph(text('See '), text('the docs', link), text(', '), text('now', strong), text('.'))),
|
||||
])
|
||||
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]- <http://y> or <a@b.c>\n'), normal(node('expand', { title: 'http://y or a@b.c' }, 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.'))])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user