diff --git a/browser-tests/convert-corpus.js b/browser-tests/convert-corpus.js index dc8eeec..6db88b9 100644 --- a/browser-tests/convert-corpus.js +++ b/browser-tests/convert-corpus.js @@ -2,12 +2,13 @@ try { const { adfToHtml, adfToLosslessMarkdown, htmlToAdf, losslessMarkdownToAdf, readAdfDocument } = await import('/dist/index.js') // WebDriver's JSON reads -0 back as 0, so a document crosses as JSON text with -0 tagged; run.js revives it. const spelled = (result) => (result.ok ? { ok: true, value: JSON.stringify(result.value, (_, value) => (Object.is(value, -0) ? '\u0000-0' : value)) } : result) - // A viewer/editor app posts the page's innerHTML back, so htmlToAdf must read what the browser writes. + // A viewer/editor app posts the page's innerHTML back, so htmlToAdf must read what the browser writes, an expand its user opened included. const throughInnerHtml = (adf) => { const html = adfToHtml(adf) if (!html.ok) return { parsed: html } const page = document.createElement('div') page.innerHTML = html.value + for (const details of page.querySelectorAll('details')) details.open = true return { parsed: spelled(htmlToAdf(page.innerHTML)) } } window.convertCorpus = (corpus) => ({ diff --git a/browser-tests/run.js b/browser-tests/run.js index aefdc87..3af8085 100644 --- a/browser-tests/run.js +++ b/browser-tests/run.js @@ -70,7 +70,7 @@ async function whenDriverAnswers() { } } -// Documents holding what a browser's innerHTML spells other than adfToHtml does (WHATWG HTML §13.3): a raw ",  , and in an attribute value < and > escaped or not, by version. +// Documents holding what a browser's innerHTML spells other than adfToHtml does (WHATWG HTML §13.3): a raw ",  , and in an attribute value < and > escaped or not, by version. convert-corpus.js opens every expand before it reads innerHTML. const text = (value, ...marks) => (marks.length === 0 ? { text: value, type: 'text' } : { marks, text: value, type: 'text' }) const browserDocuments = [ { @@ -86,6 +86,14 @@ const browserDocuments = [ }), name: 'quotes, no-break spaces and angle brackets', }, + { + json: JSON.stringify({ + content: [{ attrs: { localId: '0199f4c2-8b1e-7d03-9a6f-2c5e8d71b4a0', title: 'More' }, content: [{ content: [text('Hidden')], type: 'paragraph' }], type: 'expand' }], + type: 'doc', + version: 1, + }), + name: 'an expand its user opened', + }, ] const corpus = { browserDocuments, diff --git a/src/html/parse/html-to-adf.test.ts b/src/html/parse/html-to-adf.test.ts index 1ef13ed..aeff6a8 100644 --- a/src/html/parse/html-to-adf.test.ts +++ b/src/html/parse/html-to-adf.test.ts @@ -259,9 +259,6 @@ test('reads a paragraph or heading with a data-indent-level attribute as indente assert.deepEqual(read(htmlToAdf('

x

\n')), document({ attrs: { level: 2 }, content: [text('x')], marks: [indentation(6)], type: 'heading' })) assert.deepEqual(read(htmlToAdf(`

\n`)), document({ attrs: { localId: ids.paragraph }, marks: [indentation(1)], type: 'paragraph' })) assert.deepEqual(read(htmlToAdf('\n')), document({ content: [item({ content: [text('x')], marks: [indentation(3)], type: 'paragraph' })], type: 'bulletList' })) - for (const html of ['

x

\n', '

x

\n', '

x

\n', '

x

\n', '

x

\n', '

x

\n', '

x

\n', `

x

\n`, '

x

\n', '
\n

x

\n
\n']) { - assert.notEqual(refusal(htmlToAdf(html)), 'read', html) - } }) test('reads a paragraph or heading with a style attribute as aligned, right as end', () => { @@ -740,6 +737,11 @@ const pinnedRefusals: readonly (readonly [string, string])[] = [ ['

a

\n', 'unmappable-html at /content/0: style on

holds text-align:center or text-align:right'], ['

a

\n', 'unmappable-html at /content/0: style on

holds text-align:center or text-align:right'], ['

a

\n', 'unmappable-html at /content/0: data-indent-level on

holds a whole number from 1 to 6'], + ['

a

\n', 'unmappable-html at /content/0: data-indent-level on

holds a whole number from 1 to 6'], + ['

a

\n', 'unmappable-html at /content/0: data-indent-level on

holds a whole number from 1 to 6'], + ['

a

\n', 'unmappable-html at /content/0: data-indent-level on

holds a whole number from 1 to 6'], + ['

a

\n', 'unmappable-html at /content/0:

takes no style attribute'], + ['

\n

a

\n
\n', 'unsupported-node-shape at /content/0:
takes no data-indent-level attribute'], ['

a

\n', 'unmappable-html at /content/0: data-indent-level on

holds a whole number from 1 to 6'], ['

a

\n', 'unmappable-html at /content/0:

takes data-indent-level once, first, before its data-* attributes'], ['

a

\n', 'unmappable-html at /content/0:

takes data-indent-level once, first, before its data-* attributes'],