3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-21 23:46:21 +01:00

Answer stability round 2: 1 🔴, 0 🟡 (0 misread); a line gives up every highlight run whose own delimiters cannot flank in one pass, as shipped, so a line of them re-emits once, and the reader records no highlight pairs

This commit is contained in:
2026-10-28 18:10:03 +01:00
committed by Lillem4n
parent 5107c9506b
commit 2f9a1b3540
5 changed files with 44 additions and 30 deletions
@@ -4,6 +4,7 @@ import test from 'node:test'
import type { AdfAttributes, AdfDocument, AdfMark, AdfNode } from '../../adf/document.ts'
import { adfToPortableMarkdown, reduceToPortable } from './adf-to-portable-markdown.ts'
import { largestNesting } from '../../nesting.ts'
import { portableLineFallback } from '../emit/inline-line.ts'
import { portableMarkdownToAdf } from './portable-markdown-to-adf.ts'
const code: AdfMark = { type: 'code' }
@@ -393,6 +394,13 @@ test('drops the mark of the run that cannot close where it sits, and keeps the l
assert.equal(portable(paragraph(text('~', highlight), text('b'), text('日本', highlight))), '~b==日本==\n')
})
test('gives up every highlight run whose own delimiter cannot flank in one fallback, so a line of them re-emits once however many it holds', () => {
const highlight: AdfMark = { type: 'backgroundColor' }
const line = [text('a '), text('x', highlight), text('a '), text('x', highlight), text('a '), text('x', highlight), text('a')]
const runs = [1, 3, 5].map((index) => ({ depth: 0, first: index, last: index }))
assert.deepEqual(portableLineFallback(line, 'paragraph', []), { ok: true, value: { kind: 'unspellable-run', runs } })
})
test('breaks a line at a newline and trims whitespace at every edge CommonMark strips', () => {
assert.equal(portable(paragraph(text(' \n a \n b\n'))), 'a\\\nb\n')
assert.equal(portable(paragraph({ type: 'hardBreak' }, text('a'), { attrs: { text: '\n' }, type: 'hardBreak' }, text('b'), { type: 'hardBreak' })), 'a\\\nb\n')