mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-19 14:45:44 +01:00
Keep the inline carry's path as it was
This commit is contained in:
+4
-4
@@ -9,11 +9,11 @@ export function blockCarry(node: AdfNode, path: ConvertErrorPath): Result<string
|
||||
return json.ok ? success(`{adf:display=block}\n${closingMacroEscaped(json.value.json)}\n{adf}`) : json
|
||||
}
|
||||
|
||||
// One macro per node, since Jira reads a node and never an array inside `{adf:display=inline}`; `first` is `nodes[0]`'s index in the content of the node at `path`.
|
||||
export function inlineCarry(nodes: readonly AdfNode[], path: ConvertErrorPath, first: number): Result<string> {
|
||||
// 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<string> {
|
||||
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}`
|
||||
}
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -7,11 +7,7 @@ const alwaysEscaped = '[]{}|'
|
||||
const delimiters = '*+-^_~'
|
||||
const lineStartMarkers = '#*-'
|
||||
const lineStartWords = /^(?:bq|h[1-6])\./i
|
||||
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 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<number> | undefined {
|
||||
const stops = new Set<number>()
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user