mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-19 22:55:44 +01:00
Ship htmlToAdf: read back exactly the HTML adfToHtml writes, a carry element from its data-adf alone, any other HTML refused
This commit is contained in:
@@ -6,6 +6,7 @@ import test from 'node:test'
|
||||
|
||||
import { adfToHtml } from '../html/emit/adf-to-html.ts'
|
||||
import { adfToLosslessMarkdown } from '../markdown/emit/adf-to-markdown.ts'
|
||||
import { htmlToAdf } from '../html/parse/html-to-adf.ts'
|
||||
import { isAdfDocument } from '../adf/document.ts'
|
||||
import { isJsonValue } from '../json-value.ts'
|
||||
import { losslessMarkdownToAdf } from '../markdown/parse/markdown-to-adf.ts'
|
||||
@@ -150,6 +151,16 @@ for (const name of names(realPayloadsRoot, '.json')) {
|
||||
})
|
||||
}
|
||||
|
||||
for (const name of names(realPayloadsRoot, '.json')) {
|
||||
test(`real-payloads/${name} writes HTML that reads back to it`, () => {
|
||||
const payload: unknown = JSON.parse(readFileSync(join(realPayloadsRoot, `${name}.json`), 'utf8'))
|
||||
assert.ok(isAdfDocument(payload), `${name}.json is not an ADF document`)
|
||||
const written = adfToHtml(payload)
|
||||
assert.ok(written.ok, written.ok ? '' : `${written.error.code}: ${written.error.message}`)
|
||||
assert.deepEqual(htmlToAdf(written.value), { ok: true, value: payload })
|
||||
})
|
||||
}
|
||||
|
||||
// The opening tag of each block type whose only attributes are `localId`, `level` and `order`, as the editor writes them.
|
||||
const blockElements: Readonly<Record<string, string>> = { blockquote: '<blockquote', bulletList: '<ul', heading: '<h', orderedList: '<ol', paragraph: '<p', rule: '<hr' }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user