diff --git a/src/html/parse/carry-element.ts b/src/html/parse/carry-element.ts index 5fc989d..cec1bea 100644 --- a/src/html/parse/carry-element.ts +++ b/src/html/parse/carry-element.ts @@ -30,12 +30,10 @@ export function readCarry(html: string, tag: StartTag, element: 'div' | 'span', // Every way the dialect spells the element, so a refusal names the one meant. function spellings(element: 'div' | 'span'): string { - const classes = [...classesOfElement(element), ...(element === 'div' ? [mediaGroupClass, panelClass] : [])].sort().map((name) => `"${name}"`) - const last = classes.pop() - const opens = last === undefined ? [] : [`opens with class=${classes.length === 0 ? last : `${classes.join(', ')} or ${last}`}`] - const others = [...opens, ...(element === 'span' ? [`holds ${colourAttributeOn(element)} alone`] : [])] - const final = others.pop() - return `is a carry element, holding class="adf-carry" and then data-adf alone${others.map((other) => `, ${other}`).join('')}${final === undefined ? '' : `, or ${final}`}` + const carry = 'is a carry element, holding class="adf-carry" and then data-adf alone' + if (element === 'div') return `${carry}, or opens with class="${mediaGroupClass}" or "${panelClass}"` + const classes = classesOfElement(element).map((name) => `"${name}"`).join(', ').replace(/, (?=[^,]*$)/, ' or ') + return `${carry}, opens with class=${classes}, or holds ${colourAttributeOn(element)} alone` } function heldNode(json: string, levels: number, html: string, jsonAt: number): Read { diff --git a/src/html/parse/html-to-adf.test.ts b/src/html/parse/html-to-adf.test.ts index e01acbd..b5d98cb 100644 --- a/src/html/parse/html-to-adf.test.ts +++ b/src/html/parse/html-to-adf.test.ts @@ -308,7 +308,7 @@ test('reads a table back, its rows, cells and attributes as adfToHtml writes the read(htmlToAdf('\n\n\n\n
x
\n')), document({ attrs: { layout: 'wide', width: 760 }, content: [{ attrs: { localId: 'r1' }, content: [{ attrs: { background: '#fffae6', colspan: 2, colwidth: [120, 80], localId: 'c1', rowspan: 3, valign: 'top' }, content: [paragraph(text('x'))], type: 'tableCell' }], type: 'tableRow' }], type: 'table' }), ) - assert.deepEqual(read(htmlToAdf('\n\n\n\n
x
\n')), document({ content: [row({ attrs: { background: '#fffae6', colspan: 2, colwidth: [120] }, content: [paragraph(text('x'))], type: 'tableCell' })], type: 'table' })) + assert.deepEqual(read(htmlToAdf('\n\n\n\n
x
\n')), document({ content: [row({ attrs: { background: 'yellow', colspan: 2, colwidth: [120] }, content: [paragraph(text('x'))], type: 'tableCell' })], type: 'table' })) assert.deepEqual(read(htmlToAdf('\n')), document({ content: [item({ type: 'table' })], type: 'bulletList' })) }) @@ -334,6 +334,7 @@ const tableRefusals: readonly (readonly [string, string])[] = [ ['\n\n\n\n
a
\n', 'unmappable-html'], ['\n\n\n\n
a
\n', 'unmappable-html'], ['\n\n\n\n
a
\n', 'unmappable-html'], + ['\n\n\n\n
a
\n', 'unmappable-html'], ['\n\n\n\n
a
\n', 'unmappable-html'], ['\n\n\n\n
a
\n', 'unmappable-html'], ['\n\n\n\n
a
\n', 'unmappable-html'], @@ -754,6 +755,8 @@ const pinnedRefusals: readonly (readonly [string, string])[] = [ ['

a b

\n', 'unmappable-html at /content/0/content/1: a of the dialect is a carry element, holding class="adf-carry" and then data-adf alone, opens with class="adf-emoji", "adf-mention" or "adf-status", or holds data-text-color alone: found ""…'], ['

a b

\n', 'unmappable-html at /content/0/content/1: a of the dialect is a carry element, holding class="adf-carry" and then data-adf alone, opens with class="adf-emoji", "adf-mention" or "adf-status", or holds data-text-color alone: found ""…'], ['

a b

\n', 'unmappable-html at /content/0/content/1: a of the dialect holds data-background-color alone: found "\n\na\n\n\n', 'unmappable-html at /content/0/content/0/content/0: style on spells no value adfToHtml writes there'], + ['\n\n\n\n
a
\n', 'unmappable-html at /content/0/content/0/content/0: takes colspan, rowspan, data-background-color and data-colwidth first, each once and in that order: found data-background-color out of place'], ['

a b

\n', 'unmappable-html at /content/0/content/1: a of the dialect holds data-background-color alone: found "b

\\n"'], ['

a

\n', 'unmappable-html at /content/0:
holds
straight after it, or a line feed and its first block: found "

a

\\n"'], ['
  • a
\n', 'unmappable-html at /content/0:
    holds
straight after it, or a line feed and its first item: found "
  • a
  • \\n"'], diff --git a/src/html/text-block-attributes.ts b/src/html/text-block-attributes.ts index a209f6c..39cfddd 100644 --- a/src/html/text-block-attributes.ts +++ b/src/html/text-block-attributes.ts @@ -24,7 +24,8 @@ function markAttribute(mark: AdfMark): string | undefined { const attrs = nodeAttrs(mark) if (Object.keys(attrs).length !== 1) return undefined const { align, level } = attrs - if (mark.type === 'alignment') return typeof align === 'string' && alignments.includes(align) ? ` ${alignAttribute}="${align}"` : undefined + const alignment = alignments.find((name) => name === align) + if (mark.type === 'alignment') return alignment === undefined ? undefined : ` ${alignAttribute}="${alignment}"` return mark.type === 'indentation' && typeof level === 'number' && indentLevels.includes(String(level)) ? ` ${indentAttribute}="${level}"` : undefined }