mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-13 12:18:28 +01:00
Read two lists a link reference definition parts as two lists, and put the changelog's breaking entries first
This commit is contained in:
@@ -75,6 +75,8 @@ type ContainerStack = {
|
||||
|
||||
type Walk = ParsedBlocks & {
|
||||
claims: Claims
|
||||
// The block a paragraph of link reference definitions alone last closed after, which ends a list as any block does.
|
||||
definedAfter: Block | undefined
|
||||
leaf: OpenLeaf | undefined
|
||||
leafOpeners: Map<Block[], Map<string, LeafOpener>>
|
||||
position: SourcePosition
|
||||
@@ -89,6 +91,7 @@ export function parseBlocks(markdown: string, claims: Claims): ParsedBlocks {
|
||||
const walk: Walk = {
|
||||
blocks: [],
|
||||
claims,
|
||||
definedAfter: undefined,
|
||||
definitions: new Map(),
|
||||
leaf: undefined,
|
||||
leafOpeners: new Map(),
|
||||
@@ -251,7 +254,7 @@ function openedList(walk: Walk, start: Extract<ContainerStart, { kind: 'item' }>
|
||||
if (!start.fresh) return start.list
|
||||
const blocks = currentBlocks(walk)
|
||||
const previous = blocks.at(-1)
|
||||
if ((previous?.kind === 'bulletList' || previous?.kind === 'orderedList') && continuesList(previous, start.list)) return previous
|
||||
if ((previous?.kind === 'bulletList' || previous?.kind === 'orderedList') && previous !== walk.definedAfter && continuesList(previous, start.list)) return previous
|
||||
blocks.push(start.list)
|
||||
return start.list
|
||||
}
|
||||
@@ -514,7 +517,10 @@ function takeParagraph(walk: Walk): Extract<Block, { kind: 'paragraph' }> | unde
|
||||
if (leaf?.kind !== 'paragraph') return undefined
|
||||
walk.leaf = undefined
|
||||
const text = readLinkDefinitions(walk.definitions, leaf.lines.join('\n'))
|
||||
if (text === '') return undefined
|
||||
if (text === '') {
|
||||
walk.definedAfter = currentBlocks(walk).at(-1)
|
||||
return undefined
|
||||
}
|
||||
const kept = leaf.positions[leaf.lines.length - text.split('\n').length]
|
||||
return { kind: 'paragraph', position: kept ?? leaf.position, text }
|
||||
}
|
||||
|
||||
@@ -673,10 +673,18 @@ test('reads a bullet list, the marker width setting the continuation', () => {
|
||||
assert.deepEqual(content(losslessMarkdownToAdf('- Code.\n')), [bulletList(item({ content: [text('Code.')], type: 'codeBlock' }))])
|
||||
assert.deepEqual(content(losslessMarkdownToAdf('- a\n-\n\n- c\n')), [bulletList(item(paragraph('a')), item(), item(paragraph('c')))])
|
||||
assert.deepEqual(content(losslessMarkdownToAdf('- a\n1. b\n')), [bulletList(item(paragraph('a'))), orderedList(1, item(paragraph('b')))])
|
||||
assert.deepEqual(content(losslessMarkdownToAdf('- a\n\n[r]: /u\n\n- b\n')), [bulletList(item(paragraph('a')), item(paragraph('b')))])
|
||||
assert.deepEqual(content(losslessMarkdownToAdf('-\n\n Part.\n')), [bulletList(item()), paragraph('Part.')])
|
||||
})
|
||||
|
||||
test('reads two lists a link reference definition parts as two lists, in every reader', () => {
|
||||
for (const read of [commonMarkToAdf, losslessMarkdownToAdf, portableMarkdownToAdf]) {
|
||||
assert.deepEqual(content(read('- a\n\n[r]: /u\n\n- b\n')), [bulletList(item(paragraph('a'))), bulletList(item(paragraph('b')))])
|
||||
assert.deepEqual(content(read('- a\n\n[r]: /u\n- b\n')), [bulletList(item(paragraph('a'))), bulletList(item(paragraph('b')))])
|
||||
assert.deepEqual(content(read('-\n\n[r]: /u\n\n- b\n')), [bulletList(item()), bulletList(item(paragraph('b')))])
|
||||
assert.deepEqual(content(read('- a\n\n [r]: /u\n- b\n')), [bulletList(item(paragraph('a')), item(paragraph('b')))])
|
||||
}
|
||||
})
|
||||
|
||||
test('reads an ordered list, its first marker the order attribute', () => {
|
||||
assert.deepEqual(content(losslessMarkdownToAdf('9. Bolt M8\n10. Nut M8\n')), [orderedList(9, item(paragraph('Bolt M8')), item(paragraph('Nut M8')))])
|
||||
assert.deepEqual(content(losslessMarkdownToAdf('1) Loosen the clamp\n')), [orderedList(1, item(paragraph('Loosen the clamp')))])
|
||||
|
||||
Reference in New Issue
Block a user