diff --git a/src/wiki/carry.ts b/src/wiki/carry.ts index ad677ea..9a88bc5 100644 --- a/src/wiki/carry.ts +++ b/src/wiki/carry.ts @@ -9,11 +9,11 @@ export function blockCarry(node: AdfNode, path: ConvertErrorPath): Result { +// One macro per node, since Jira reads a node and never an array inside `{adf:display=inline}`. +export function inlineCarry(nodes: readonly AdfNode[], path: ConvertErrorPath): Result { let macros = '' - for (const [index, node] of nodes.entries()) { - const json = carriedJson(node, node, 'compact', [...path, 'content', first + index], largestNesting) + for (const node of nodes) { + const json = carriedJson(node, node, 'compact', path, largestNesting) if (!json.ok) return json macros += `{adf:display=inline}${closingMacroEscaped(json.value.json)}{adf}` } diff --git a/src/wiki/emit/adf-to-jira-wiki.test.ts b/src/wiki/emit/adf-to-jira-wiki.test.ts index 61a6f44..59d256c 100644 --- a/src/wiki/emit/adf-to-jira-wiki.test.ts +++ b/src/wiki/emit/adf-to-jira-wiki.test.ts @@ -339,14 +339,6 @@ test('carries a text holding a pipe in a table cell, where a backslash would end 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', () => { let value: AdfAttributes[string] = 1 for (let level = 0; level < largestNesting - 1; level += 1) value = [value] diff --git a/src/wiki/emit/inline-line.ts b/src/wiki/emit/inline-line.ts index e32a80a..1550a80 100644 --- a/src/wiki/emit/inline-line.ts +++ b/src/wiki/emit/inline-line.ts @@ -34,7 +34,7 @@ export function inlineLine(nodes: readonly AdfNode[], path: ConvertErrorPath, in const after = following?.marks.length === 0 ? following.spelled?.text : undefined const written = groupSpelling(atoms.slice(first, last + 1), lastCharacter(line), after === undefined ? undefined : firstCharacter(after)) if (written === undefined) { - const carry = inlineCarry(nodes.slice(first, last + 1), path, first) + const carry = inlineCarry(nodes.slice(first, last + 1), [...path, 'content', first]) if (!carry.ok) return carry line += carry.value carried = true diff --git a/src/wiki/emit/text-escaping.ts b/src/wiki/emit/text-escaping.ts index 90a8084..dcac3d9 100644 --- a/src/wiki/emit/text-escaping.ts +++ b/src/wiki/emit/text-escaping.ts @@ -7,11 +7,7 @@ const alwaysEscaped = '[]{}|' const delimiters = '*+-^_~' const lineStartMarkers = '#*-' const lineStartWords = /^(?:bq|h[1-6])\./i -const smileysByOpener = new Map() -for (const smiley of smileys) { - const opener = smiley.charAt(0) - smileysByOpener.set(opener, [...(smileysByOpener.get(opener) ?? []), { characters: Array.from(smiley), parenthesised: /[()]/.test(smiley) }]) -} +const smileyCharacters = smileys.map((smiley) => ({ 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. @@ -43,7 +39,8 @@ function escapes(character: string, characters: readonly string[], index: number function smileyStops(characters: readonly string[], end: Side): Set | undefined { const stops = new Set() for (const [index, character] of characters.entries()) { - for (const { characters: spelled, parenthesised } of smileysByOpener.get(character) ?? []) { + for (const { characters: spelled, parenthesised } of smileyCharacters) { + if (spelled[0] !== character) continue const held = characters.slice(index, index + spelled.length) if (held.some((heldCharacter, offset) => heldCharacter !== spelled[offset])) continue const cut = held.length < spelled.length