3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-20 15:15:44 +01:00

Find code-span and link openers and unspellable mark runs by reading the escaped line back

This commit is contained in:
2026-10-28 19:11:23 +01:00
committed by Lillem4n
parent c295611a9b
commit b0bf362ef9
12 changed files with 193 additions and 251 deletions
@@ -342,6 +342,15 @@ test('escapes only text that would otherwise open a construct', () => {
assert.equal(emitted('x"_y"'), 'x"\\_y"\n')
})
test('escapes every text bracket in a line where one opens link text, and every text backtick where one opens a code span', () => {
const emitted = (text: string): string => markdown(adfToLosslessMarkdown(document(paragraph({ text, type: 'text' }))))
assert.equal(emitted('[a](b) [c]'), '\\[a](b) \\[c]\n')
assert.equal(emitted('see [1] and [docs](url) [2]'), 'see \\[1] and \\[docs](url) \\[2]\n')
assert.equal(emitted('[a] b](c'), '[a] b](c\n')
assert.equal(emitted('[x]('), '[x](\n')
assert.equal(emitted('Use ` or ``code`` syntax'), 'Use \\` or \\`\\`code\\`\\` syntax\n')
})
test('escapes a heading closing sequence', () => {
const heading = (text: string): string => markdown(adfToLosslessMarkdown(document({ attrs: { level: 2 }, content: [{ text, type: 'text' }], type: 'heading' })))
assert.equal(heading('done #'), '## done \\#\n')