mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-18 22:25:44 +01:00
Answer stability round 1: 0 🔴, 2 🟡 (0 misread); open every expand in the browser leg, pin the indentation refusals with their messages
This commit is contained in:
@@ -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) => ({
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -259,9 +259,6 @@ test('reads a paragraph or heading with a data-indent-level attribute as indente
|
||||
assert.deepEqual(read(htmlToAdf('<h2 data-indent-level="6">x</h2>\n')), document({ attrs: { level: 2 }, content: [text('x')], marks: [indentation(6)], type: 'heading' }))
|
||||
assert.deepEqual(read(htmlToAdf(`<p data-indent-level="1" data-local-id="${ids.paragraph}"></p>\n`)), document({ attrs: { localId: ids.paragraph }, marks: [indentation(1)], type: 'paragraph' }))
|
||||
assert.deepEqual(read(htmlToAdf('<ul>\n<li><p data-indent-level="3">x</p></li>\n</ul>\n')), document({ content: [item({ content: [text('x')], marks: [indentation(3)], type: 'paragraph' })], type: 'bulletList' }))
|
||||
for (const html of ['<p data-indent-level="0">x</p>\n', '<p data-indent-level="7">x</p>\n', '<p data-indent-level="02">x</p>\n', '<p data-indent-level="1.5">x</p>\n', '<p data-indent-level="">x</p>\n', '<p data-indent-level="2" style="text-align:center">x</p>\n', '<p style="text-align:center" data-indent-level="2">x</p>\n', `<p data-local-id="${ids.paragraph}" data-indent-level="2">x</p>\n`, '<p data-indent-level="2" data-indent-level="2">x</p>\n', '<blockquote data-indent-level="2">\n<p>x</p>\n</blockquote>\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])[] = [
|
||||
['<p style="color:red">a</p>\n', 'unmappable-html at /content/0: style on <p> holds text-align:center or text-align:right'],
|
||||
['<h1 style="text-align:left">a</h1>\n', 'unmappable-html at /content/0: style on <h1> holds text-align:center or text-align:right'],
|
||||
['<p data-indent-level="7">a</p>\n', 'unmappable-html at /content/0: data-indent-level on <p> holds a whole number from 1 to 6'],
|
||||
['<p data-indent-level="0">a</p>\n', 'unmappable-html at /content/0: data-indent-level on <p> holds a whole number from 1 to 6'],
|
||||
['<p data-indent-level="02">a</p>\n', 'unmappable-html at /content/0: data-indent-level on <p> holds a whole number from 1 to 6'],
|
||||
['<p data-indent-level="1.5">a</p>\n', 'unmappable-html at /content/0: data-indent-level on <p> holds a whole number from 1 to 6'],
|
||||
['<p data-indent-level="2" style="text-align:center">a</p>\n', 'unmappable-html at /content/0: <p> takes no style attribute'],
|
||||
['<blockquote data-indent-level="2">\n<p>a</p>\n</blockquote>\n', 'unsupported-node-shape at /content/0: <blockquote> takes no data-indent-level attribute'],
|
||||
['<h3 data-indent-level="">a</h3>\n', 'unmappable-html at /content/0: data-indent-level on <h3> holds a whole number from 1 to 6'],
|
||||
['<p data-local-id="p1" data-indent-level="2">a</p>\n', 'unmappable-html at /content/0: <p> takes data-indent-level once, first, before its data-* attributes'],
|
||||
['<p data-indent-level="2" data-indent-level="2">a</p>\n', 'unmappable-html at /content/0: <p> takes data-indent-level once, first, before its data-* attributes'],
|
||||
|
||||
Reference in New Issue
Block a user