3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-20 07:05:44 +01:00

Answer architecture round 1: 0 🔴, 11 🟡 (0 misread); one line policy, one reduction run, named sweep stages, spelling memo, block text, link options, HTML refusals

This commit is contained in:
2026-11-08 20:30:08 +01:00
committed by Lillem4n
parent 8e6d7efff1
commit e9de121425
20 changed files with 329 additions and 215 deletions
+11 -5
View File
@@ -18,7 +18,7 @@ import { positioned, success } from '../../result.ts'
import { readAnchorAttributes } from '../anchor-element.ts'
import { readCarry } from './carry-element.ts'
import { readCarryAttributes } from '../carry-attributes.ts'
import { readDataAttributes } from '../data-attributes.ts'
import { readDataAttributes, readDataAttributesAfter } from '../data-attributes.ts'
import { readImageAttributes } from '../image-element.ts'
import { readLanguageClass } from '../language-class.ts'
import { serializeCanonicalJson } from '../../canonical-json.ts'
@@ -242,7 +242,8 @@ function readContainer(html: string, tag: StartTag, type: ContainerType, place:
const at = tag.start + `<${tag.name} start="`.length
return refused('unmappable-html', `an ordered list starts at an integer, written as JavaScript writes it: ${foundAt(html, at)}`, html, at, place)
}
const data = readDataAttributes(tag.attributes, tag.name, blockNodes[type].attributes, ordered ? ['order'] : [], ordered ? 'start' : undefined)
const vocabulary = blockNodes[type].attributes
const data = ordered ? readDataAttributesAfter('start', tag.attributes, tag.name, vocabulary, ['order']) : readDataAttributes(tag.attributes, tag.name, vocabulary, [])
if (data.fault !== undefined) return refused(data.fault.code, data.fault.message, html, tag.start, place)
const node = built(type, order === undefined ? data.value : { order, ...data.value }, [])
const closer = `</${tag.name}>`
@@ -320,9 +321,7 @@ function readItemLine(html: string, index: number, element: string, open: Open):
if (!line.ok) return line
const { end, node } = line.value
if (!html.startsWith(closer, end) && !html.startsWith('\n', end)) {
const lineEnd = `the line ends at ${closer}, or at a line feed before the next block`
// After a line's `</p>`, or before a block or the next item, no inline element can stand.
const stop = line.value.form === 'bare' && !isBlockStart(html, end) && startTagName(html, end) !== element ? misread(html, end, `${lineEnd}, and its text spells < as &lt;`, 'no inline element of the dialect') : { at: end, message: `${lineEnd}: ${foundAt(html, end)}` }
const stop = lineEndRefusal(html, end, line.value.form, element)
return refused('unmappable-html', stop.message, html, stop.at, open.place)
}
const paragraph = asFirstParagraph({ end, node }, line.value.form, html, index, place)
@@ -331,6 +330,13 @@ function readItemLine(html: string, index: number, element: string, open: Open):
return success({ end: end + 1, kind: 'opened', open: { ...open, content: [node] } })
}
function lineEndRefusal(html: string, end: number, form: FirstParagraphForm, element: string): { at: number; message: string } {
const lineEnd = `the line ends at </${element}>, or at a line feed before the next block`
// After a line's `</p>`, or before a block or the next item, no inline element can stand.
if (form !== 'bare' || isBlockStart(html, end) || startTagName(html, end) === element) return { at: end, message: `${lineEnd}: ${foundAt(html, end)}` }
return misread(html, end, `${lineEnd}, and its text spells < as &lt;`, 'no inline element of the dialect')
}
// The paragraph on an item's or cell's line and the form it stands in there, up to its closer or to the line feed before its next block.
function readLineParagraph(html: string, index: number, place: Place): Result<{ end: number; form: FirstParagraphForm; node: AdfNode }, ParseError> {
const tag = readStartTag(html, index)