12c: the block directive forms read and spell !adf: openers and closers
This commit is contained in:
@@ -119,55 +119,6 @@ test('no round-trip fixture repeats the document another holds', () => {
|
||||
}
|
||||
})
|
||||
|
||||
// spec/flavour.md, Directives: the container fence rule, checked against the emitted bytes.
|
||||
function fenceNestingFault(markdown: string): string | undefined {
|
||||
const open: number[] = []
|
||||
let codeFence: string | undefined
|
||||
for (const line of markdown.split('\n')) {
|
||||
const content = line.replace(/^[ \t]*(?:(?:> ?|[-*+] |\d{1,9}[.)] )[ \t]*)*/, '')
|
||||
const backticks = /^(`{3,}|~{3,})/.exec(content)?.[1]
|
||||
if (codeFence !== undefined) {
|
||||
if (backticks !== undefined && backticks[0] === codeFence[0] && backticks.length >= codeFence.length) codeFence = undefined
|
||||
continue
|
||||
}
|
||||
if (backticks !== undefined) {
|
||||
codeFence = backticks
|
||||
continue
|
||||
}
|
||||
const colons = /^(:{2,})(.*)$/.exec(content)
|
||||
if (colons === null) continue
|
||||
const run = colons[1]?.length ?? 0
|
||||
const enclosing = open[open.length - 1]
|
||||
if (colons[2] === '') {
|
||||
if (enclosing === undefined) return `${JSON.stringify(line)} closes no open container`
|
||||
if (run < enclosing) return `${JSON.stringify(line)} is shorter than the ${enclosing} colons it would close`
|
||||
open.pop()
|
||||
continue
|
||||
}
|
||||
if (enclosing !== undefined && run >= enclosing) return `${JSON.stringify(line)} sits in a container fenced with ${enclosing} colons`
|
||||
if (run > 2) open.push(run)
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
test('the fence nesting check catches a fence a container cannot hold', () => {
|
||||
assert.equal(fenceNestingFault(':::panel info\n- :::panel warning\n B\n :::\n:::'), '"- :::panel warning" sits in a container fenced with 3 colons')
|
||||
assert.equal(fenceNestingFault(':::panel info\n- - :::panel warning\n B\n :::\n:::'), '"- - :::panel warning" sits in a container fenced with 3 colons')
|
||||
assert.equal(fenceNestingFault(':::panel info\n10. :::panel warning\n B\n :::\n:::'), '"10. :::panel warning" sits in a container fenced with 3 colons')
|
||||
assert.equal(fenceNestingFault('::::panel info\n:::\n::::'), '":::" is shorter than the 4 colons it would close')
|
||||
assert.equal(fenceNestingFault('Text\n:::\n'), '":::" closes no open container')
|
||||
assert.equal(fenceNestingFault('::::panel info\n- - :::panel warning\n B\n :::\n::::'), undefined)
|
||||
assert.equal(fenceNestingFault(':::tableCell\n```text\n:::::::panel warning\n:::\n```\n:::'), undefined)
|
||||
})
|
||||
|
||||
for (const directory of roundTripDirectories) {
|
||||
for (const name of fixtureNames(directory, '.md')) {
|
||||
test(`${directory}/${name} fences every container longer than its body`, () => {
|
||||
assert.equal(fenceNestingFault(readFileSync(join(roundTripRoot, directory, `${name}.md`), 'utf8')), undefined)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
for (const name of pairedNames(normalizationRoot, '.md', '.json')) {
|
||||
test(`normalization/${name} parses to the document beside it, which emits and reads back to itself`, () => {
|
||||
const expected: unknown = JSON.parse(readFileSync(join(normalizationRoot, `${name}.json`), 'utf8'))
|
||||
|
||||
Reference in New Issue
Block a user