3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-13 04:08:29 +01:00

Answer stability round 1: 1 🔴, 2 🟡; read a quote marker behind a split tab's leftover columns as text, and pin the tab cases

This commit is contained in:
2026-10-18 12:05:27 +02:00
committed by Lillem4n
parent a140f5a244
commit 2fb5366952
2 changed files with 30 additions and 3 deletions
+26
View File
@@ -152,3 +152,29 @@ test('stops a blank line at an empty item, and gives a code block in an item the
{ kind: 'code', language: '', position: { line: 1, offset: 0 }, text: '\nx' },
])
})
function outline(blocks: readonly Block[]): string {
return blocks
.map((block) => {
if (block.kind === 'blockquote') return `quote(${outline(block.blocks)})`
if (block.kind === 'bulletList') return `list(${block.items.map(outline).join(',')})`
if (block.kind === 'code') return `code(${JSON.stringify(block.text)})`
if (block.kind === 'paragraph') return `paragraph(${block.text.split('\n').map((line) => line.trim()).join('|')})`
return block.kind
})
.join(' ')
}
test('reads a marker a tab pushes to four columns past its container as text, not as a marker', () => {
const read = (markdown: string): string => outline(parseBlocks(markdown, flavourClaims.lossless).blocks)
assert.equal(read('> a\n \t> b\n'), 'quote(paragraph(a|> b))')
assert.equal(read('> > a\n>\t\t> b\n'), 'quote(quote(paragraph(a|> b)))')
assert.equal(read('- > a\n\t\t> b\n'), 'list(quote(paragraph(a|> b)))')
assert.equal(read('x\n\t# h\n'), 'paragraph(x|# h)')
})
test('gives what follows an item the columns of the tab a cut splits', () => {
const read = (markdown: string): string => outline(parseBlocks(markdown, flavourClaims.lossless).blocks)
assert.equal(read('- ```\n\tx\n ```\n'), 'list(code(" x"))')
assert.equal(read('- a\n \t- b\n'), 'list(paragraph(a) list(paragraph(b)))')
})
+4 -3
View File
@@ -63,8 +63,9 @@ type ContainerStart = { kind: 'blockquote'; rest: Line } | { fresh: boolean; ind
type ParagraphLine = { position: SourcePosition; text: string }
// The line from an absolute column on: a tab a cut splits keeps the stop it is measured against, and its leftover columns
// stand as `spaces` before `text`, so a cut never builds a string. At most 3, which a cut of `largestOpenerIndentation` takes whole.
// They are blank, so blankness reads `text` alone; a block takes the line through `lineText`.
// stand as `spaces` before `text`, so a cut shares `text`. At most 3, and blank, so blankness reads `text` alone. A cut of
// `largestOpenerIndentation` leaves some only on a line indented as code, which no marker follows: a marker check reads
// `spaces` first, and a block takes the line through `lineText`.
type Line = { column: number; spaces: number; text: string }
type LeafOpener = { index: number; position: SourcePosition }
@@ -201,7 +202,7 @@ function continuesContainer(container: EdgeContainer, line: Line): Line | undefi
}
function blockquoteRest(opener: Line): Line | undefined {
if (!opener.text.startsWith('>')) return undefined
if (opener.spaces > 0 || !opener.text.startsWith('>')) return undefined
return removeColumns({ column: opener.column + 1, spaces: 0, text: opener.text.slice(1) }, 1)
}