3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-19 06:35:44 +01:00

Answer prose round 1: 1 🔴, 11 🟡 (0 misread); keep the spec's carry rules true to the colour and figure spellings, file the carry message and the block task item as items 186 and 187, sort the new rows and imports

This commit is contained in:
2026-11-15 03:19:18 +01:00
committed by Lillem4n
parent b9ee38823a
commit f5a2897e0f
8 changed files with 44 additions and 27 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ const listTypes: readonly TaskListType[] = ['decisionList', 'taskList']
export const expandClasses: Readonly<Record<ExpandType, string>> = { expand: 'adf-expand', nestedExpand: 'adf-nested-expand' }
export const panelClass = 'adf-panel'
// The panel type and an item's state are no attribute of the vocabularies, which a directive spells as its argument; here each is a data-* attribute like the rest.
// A panel's type is no attribute of the vocabularies, since a directive spells it as its argument; here it is a data-* attribute like the rest.
export const panelAttributes: AttributeVocabulary = { ...blockNodes.panel.attributes, panelType: 'string' }
// A task or decision list, its items' type, class and attributes.
+1 -1
View File
@@ -26,7 +26,7 @@ export function mediaImage(media: AdfNode): string | undefined {
return `${anchor}<img${attributes}>${link === undefined ? '' : '</a>'}`
}
// The attributes an `<img>` of the dialect holds, read as `readMediaImage` reads them; `fault` names no `src`, or a `class` besides one.
// The media attributes an `<img>` of the dialect holds; `fault` where its `src`, `class`, `alt`, size or `data-*` attributes are not the ones `imageAttributes` writes.
export function readMediaImage(pairs: readonly (readonly [string, string])[]): Read<AdfAttributes> {
let rest = pairs
const attrs: AdfAttributes = {}
+13
View File
@@ -640,6 +640,18 @@ test('reads panels, expands and nested expands nested 500 levels, and refuses th
}
})
test('reads a task or decision list nested 499 levels, its items one level below it, and refuses the next level', () => {
const lists = [
'<ul class="adf-task-list">\n<li class="adf-task" data-state="TODO"><input type="checkbox" disabled=""> x</li>\n</ul>',
'<ul class="adf-decision-list">\n<li class="adf-decision" data-state="DECIDED">x</li>\n</ul>',
]
const panels = (levels: number, list: string): string => `${'<div class="adf-panel">\n'.repeat(levels)}${list}${'\n</div>'.repeat(levels)}\n`
for (const list of lists) {
assert.equal(refusal(htmlToAdf(panels(499, list))), 'read')
assert.equal(refusal(htmlToAdf(panels(500, list))).startsWith('unsupported-nesting-depth'), true)
}
})
test('reads a media of no url as an <img> of class adf-media', () => {
const single = htmlToAdf('<figure class="adf-media-single"><img class="adf-media" data-type="external"></figure>\n')
assert.deepEqual(read(single), document({ content: [{ attrs: { type: 'external' }, type: 'media' }], type: 'mediaSingle' }))
@@ -662,6 +674,7 @@ const pinnedRefusals: readonly (readonly [string, string])[] = [
['<ul class="adf-task-list">\n<li data-state="TODO"><input type="checkbox" disabled=""> a</li>\n</ul>\n', 'unmappable-html at /content/0/content/0: an <li> of this list has class="adf-task" first'],
['<ul class="adf-task-list">\n<li class="adf-task" data-state="TODO"><input type="checkbox" disabled="">a</li>\n</ul>\n', 'unmappable-html at /content/0/content/0: a task item\'s text stands a space after its checkbox: found "a</li>\\n</ul>\\n"'],
['<ul class="adf-task-list">\n<li class="adf-task" data-state="TODO"><input type="checkbox" disabled=""> </li>\n</ul>\n', 'unmappable-html at /content/0/content/0: a task item holds text where a space follows its checkbox: found "</li>\\n</ul>\\n"'],
['<ul class="adf-decision-list">\n<li class="adf-decision" data-state="DECIDED"><p>a</p></li>\n</ul>\n', 'unmappable-html at /content/0/content/0: <p> as written here is no inline element of the dialect: found "<p>a</p></li>\\n</ul>\\n"'],
['<ul class="adf-task-list">\n<li class="adf-task" data-state="TODO">a</li>\n</ul>\n', 'unmappable-html at /content/0/content/0: a task item starts with <input type="checkbox" disabled="">, checked where its data-state is DONE: found "a</li>\\n</ul>\\n"'],
['<ul class="adf-task-list">\n<li class="adf-task" data-state="TODO"><input type="checkbox"> a</li>\n</ul>\n', 'unmappable-html at /content/0/content/0: a task item starts with <input type="checkbox" disabled="">, checked where its data-state is DONE: found "<input type=\\"checkbox\\"> "…'],
['<ul class="adf-task-list">\n<li class="adf-task" data-state="TODO"><input type="radio" disabled=""> a</li>\n</ul>\n', 'unmappable-html at /content/0/content/0: a task item starts with <input type="checkbox" disabled="">, checked where its data-state is DONE: found "<input type=\\"radio\\" disa"…'],
+3 -3
View File
@@ -2,17 +2,16 @@ import type { AdfDocument, AdfNode } from '../../adf/document.ts'
import type { FirstParagraphForm } from '../first-paragraph.ts'
import type { ParseError, Result } from '../../result.ts'
import { blockNodes } from '../../adf/block-nodes.ts'
import { expandClasses, expandOfClass, panelAttributes, panelClass, taskListOfClass, taskListOfType } from '../block-classes.ts'
import { built, readInlineBlock } from './inline-block.ts'
import { carryContent } from '../carry-content.ts'
import { centeredImage, externalMedia } from '../../adf/plain-image.ts'
import { isHeaderRow, readCellAttributes } from '../cell-element.ts'
import { containerElements, headingElements, headingLevel, readListStart, type ContainerType } from '../block-elements.ts'
import { expandClasses, expandOfClass, panelAttributes, panelClass, taskListOfClass, taskListOfType } from '../block-classes.ts'
import { firstParagraphForm } from '../first-paragraph.ts'
import { foundAt, misread, misspelledText, positionIn, readStartTag, refused, startTagName, type Place, type ReadNode, type StartTag } from './source.ts'
import { isHeaderRow, readCellAttributes } from '../cell-element.ts'
import { largestNesting } from '../../nesting.ts'
import { misspelledAt, unescapedValue } from '../escaping.ts'
import { readInline } from './inline.ts'
import { nodeAttrs } from '../../adf/document.ts'
import { notAString } from '../../not-a-string.ts'
import { positioned, success } from '../../result.ts'
@@ -22,6 +21,7 @@ import { readCarryAttributes } from '../carry-attributes.ts'
import { readDataAttributes, readDataAttributesAfter } from '../data-attributes.ts'
import { readFigure, readMediaGroup } from './media-block.ts'
import { readImageAttributes } from '../image-element.ts'
import { readInline } from './inline.ts'
import { readLanguageClass } from '../language-class.ts'
import { readTaskItem } from './task-item.ts'
import { serializeCanonicalJson } from '../../canonical-json.ts'
+2 -2
View File
@@ -7,7 +7,7 @@ import { success, type Read } from '../../result.ts'
import { taskLists, type TaskListType } from '../block-classes.ts'
import { taskStates } from '../task-element.ts'
// An item of a task or decision list as `adfToHtml` writes it: its checkbox, if a task, a space, then its inline content.
// An item of a task or decision list as `adfToHtml` writes it: a task item's checkbox and a space, then its inline content.
export function readTaskItem(html: string, index: number, place: Place, list: TaskListType): ReadNode {
const tag = readStartTag(html, index)
if (tag?.name !== 'li') {
@@ -33,7 +33,7 @@ export function readTaskItem(html: string, index: number, place: Place, list: Ta
if (!inline.ok) return inline
const { end, nodes } = inline.value
if (nodes.length === 0 || !html.startsWith('</li>', end)) {
const stop = nodes.length === 0 ? { at: end, message: `a task item holds text where a space follows its checkbox: ${foundAt(html, end)}` } : misread(html, end, 'an item holds inline content, then </li>, as one line', 'no inline element of the dialect')
const stop = nodes.length === 0 && done !== undefined ? { at: end, message: `a task item holds text where a space follows its checkbox: ${foundAt(html, end)}` } : misread(html, end, 'an item holds inline content, then </li>, as one line', 'no inline element of the dialect')
return refused('unmappable-html', stop.message, html, stop.at, place)
}
return success({ end: end + '</li>'.length, node: { ...node, content: nodes } })