mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-19 06:35:44 +01:00
Kill the surviving mutants of the wiki writer's cell, heading and carry-path changes
This commit is contained in:
@@ -333,7 +333,18 @@ test('escapes a smiley the node edge cuts, unless the line ends there', () => {
|
||||
test('carries a text holding a pipe in a table cell, where a backslash would end the cell', () => {
|
||||
assert.equal(wiki(table(plainTable, [cell('tableCell', text('a|b')), cell('tableCell', text('c'))])), `|${inline('{"text":"a|b","type":"text"}')}|c|`)
|
||||
assert.equal(wiki(table(plainTable, [cell('tableCell', text('x', { attrs: { href: 'https://example.com' }, type: 'link' }), text('|'))])), `|[x|https://example.com]${inline('{"text":"|","type":"text"}')}|`)
|
||||
assert.equal(wiki(table(plainTable, [cell('tableHeader', text('a|b'))])), `||${inline('{"text":"a|b","type":"text"}')}||`)
|
||||
assert.equal(line('a|b'), 'a\\|b')
|
||||
assert.equal(wiki(list('bulletList', item(paragraph(text('a|b'))))), '* a\\|b')
|
||||
assert.equal(wiki({ attrs: { level: 1 }, content: [text('a|b')], type: 'heading' }), 'h1. a\\|b')
|
||||
})
|
||||
|
||||
test('names the path of the node in a run whose carry is refused', () => {
|
||||
const background = { attrs: { color: '#ffff00' }, type: 'backgroundColor' }
|
||||
let value: AdfAttributes[string] = 1
|
||||
for (let level = 0; level < largestNesting - 1; level += 1) value = [value]
|
||||
const deep = { attrs: { a: value }, marks: [background], type: 'unknownInline' }
|
||||
assert.equal(refusal(adfToLosslessJiraWiki(document(paragraph(text('a', background), deep)))), 'unsupported-nesting-depth at /content/0/content/1')
|
||||
})
|
||||
|
||||
test('refuses a heading holding a carry past 500 levels', () => {
|
||||
|
||||
@@ -7,8 +7,11 @@ const alwaysEscaped = '[]{}|'
|
||||
const delimiters = '*+-^_~'
|
||||
const lineStartMarkers = '#*-'
|
||||
const lineStartWords = /^(?:bq|h[1-6])\./i
|
||||
const smileyOpeners = '(:;'
|
||||
const smileyCharacters = smileys.map((smiley) => ({ characters: Array.from(smiley), parenthesised: /[()]$/.test(smiley) }))
|
||||
const smileysByOpener = new Map<string, { characters: string[]; parenthesised: boolean }[]>()
|
||||
for (const smiley of smileys) {
|
||||
const opener = smiley.charAt(0)
|
||||
smileysByOpener.set(opener, [...(smileysByOpener.get(opener) ?? []), { characters: Array.from(smiley), parenthesised: /[()]/.test(smiley) }])
|
||||
}
|
||||
const unprotectable = /[\\\r\n]|https?:\/\//i
|
||||
|
||||
// spec/wiki.md, Inline: `undefined` where no backslash protects the text, so it rides the carry. `inCell`: the text stands in a table cell, where an escaped `|` still ends the cell.
|
||||
@@ -40,8 +43,7 @@ function escapes(character: string, characters: readonly string[], index: number
|
||||
function smileyStops(characters: readonly string[], end: Side): Set<number> | undefined {
|
||||
const stops = new Set<number>()
|
||||
for (const [index, character] of characters.entries()) {
|
||||
if (!smileyOpeners.includes(character)) continue
|
||||
for (const { characters: spelled, parenthesised } of smileyCharacters) {
|
||||
for (const { characters: spelled, parenthesised } of smileysByOpener.get(character) ?? []) {
|
||||
const held = characters.slice(index, index + spelled.length)
|
||||
if (held.some((heldCharacter, offset) => heldCharacter !== spelled[offset])) continue
|
||||
const cut = held.length < spelled.length
|
||||
|
||||
Reference in New Issue
Block a user