mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-18 14:15:44 +01:00
Answer stability round 1: 2 🔴, 1 🟡 (0 misread); count a task or decision list's items one level below it, write an alignment only for a string align, move the task-list row into the HTML table
This commit is contained in:
@@ -17,7 +17,8 @@ export function textBlockAttributes(node: AdfNode, vocabulary: AttributeVocabula
|
||||
const [mark, ...others] = nodeMarks(node)
|
||||
if (mark === undefined) return dataAttributes(node, vocabulary, written)
|
||||
const attrs = nodeAttrs(mark)
|
||||
const textAlign = others.length === 0 && mark.type === 'alignment' && Object.keys(attrs).length === 1 ? alignments().get(String(attrs['align'])) : undefined
|
||||
const align = attrs['align']
|
||||
const textAlign = others.length === 0 && mark.type === 'alignment' && Object.keys(attrs).length === 1 && typeof align === 'string' ? alignments().get(align) : undefined
|
||||
const bare: AdfNode = { ...node }
|
||||
delete bare.marks
|
||||
const data = textAlign === undefined ? undefined : dataAttributes(bare, vocabulary, written)
|
||||
|
||||
@@ -689,6 +689,18 @@ test('writes panels, expands and nested expands nested 500 levels, and refuses t
|
||||
}
|
||||
})
|
||||
|
||||
test('writes a task or decision list nested 499 levels, its items one level below it, and refuses the next level', () => {
|
||||
const lists: AdfNode[] = [
|
||||
{ content: [{ attrs: { state: 'TODO' }, content: [text('x')], type: 'taskItem' }], type: 'taskList' },
|
||||
{ content: [{ attrs: { state: 'DECIDED' }, content: [text('x')], type: 'decisionItem' }], type: 'decisionList' },
|
||||
]
|
||||
for (const list of lists) {
|
||||
assert.equal(refusal(adfToHtml(document(nested('panel', largestNesting - 1, list)))), 'written')
|
||||
const deep = adfToHtml(document(nested('panel', largestNesting, list)))
|
||||
assert.equal(refusal(deep).startsWith('unsupported-nesting-depth at /'), true)
|
||||
}
|
||||
})
|
||||
|
||||
test('writes a caption as a figcaption, refuses an inline carry nested past 500 in it, and carries what is no caption', () => {
|
||||
const media: AdfNode = { attrs: { type: 'external', url: 'https://example.com/moon.jpg' }, type: 'media' }
|
||||
const deep = nested('unknownInline', largestNesting, text('x'))
|
||||
@@ -709,6 +721,8 @@ test('carries a media or a paragraph whose marks only look like the ones HTML sp
|
||||
assert.equal(carriedBlock(single({ attrs: { ...external, height: 0 }, type: 'media' })), true)
|
||||
assert.equal(carriedBlock(single({ attrs: { ...external, width: 0 }, type: 'media' })), true)
|
||||
assert.equal(carriedBlock({ content: [text('x')], marks: [{ attrs: { align: 'center' }, type: 'indentation' }], type: 'paragraph' }), true)
|
||||
assert.equal(carriedBlock({ content: [text('x')], marks: [{ attrs: { align: ['center'] }, type: 'alignment' }], type: 'paragraph' }), true)
|
||||
assert.equal(carriedBlock({ attrs: { level: 1 }, content: [text('x')], marks: [{ attrs: { align: [['end']] }, type: 'alignment' }], type: 'heading' }), true)
|
||||
})
|
||||
|
||||
test('refuses, at the item\'s text, a card a link marks in a task item', () => {
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
import type { AdfDocument, AdfNode } from '../../adf/document.ts'
|
||||
import { anchorOpener } from '../anchor-element.ts'
|
||||
import { blockNodes } from '../../adf/block-nodes.ts'
|
||||
import { expandClasses, panelAttributes, panelClass, taskLists } from '../block-classes.ts'
|
||||
import { carriedBlock, carryElement } from './carry-element.ts'
|
||||
import { carryContent } from '../carry-content.ts'
|
||||
import { cellAttributes, isHeaderRow } from '../cell-element.ts'
|
||||
import { containerElements, headingElement, listStart } from '../block-elements.ts'
|
||||
import { dataAttributes } from '../data-attributes.ts'
|
||||
import { expandClasses, panelAttributes, panelClass, taskLists } from '../block-classes.ts'
|
||||
import { failure, success, type ConvertErrorPath, type Result } from '../../result.ts'
|
||||
import { firstParagraphForm } from '../first-paragraph.ts'
|
||||
import { imageElement } from '../image-element.ts'
|
||||
import { inlineHtml, writableText } from './inline.ts'
|
||||
import { isUnmarkedSpellableText, nodeAttrs, nodeContent, readAdfDocument, writableContent } from '../../adf/document.ts'
|
||||
import { itemOpener } from '../task-element.ts'
|
||||
import { languageClass } from '../language-class.ts'
|
||||
import { largestNesting } from '../../nesting.ts'
|
||||
import { longestOutput, tooLong, withinEngineLimits } from '../../length-bound.ts'
|
||||
import { mediaImage } from '../media-element.ts'
|
||||
import { plainImage } from '../../adf/plain-image.ts'
|
||||
import { serializeCanonicalJson } from '../../canonical-json.ts'
|
||||
import { itemOpener } from '../task-element.ts'
|
||||
import { textBlockAttributes } from '../alignment-element.ts'
|
||||
|
||||
// depth: the nesting level of the block list holding the node, as `largestNesting` counts it; `attributes`: the `<li>`'s, `<td>`'s or `<th>`'s, built when its list or table checked it; `lead`: what stands before the inline content of a task or decision item.
|
||||
@@ -112,7 +112,7 @@ function taskPieces({ depth, node, path }: Block, type: keyof typeof taskLists):
|
||||
const opener = itemOpener(type, item)
|
||||
if (opener === undefined) return undefined
|
||||
if (index > 0) items.push('\n')
|
||||
items.push({ ...opener, depth, kind: 'item', node: item, path: [...path, 'content', index], tag: 'li' })
|
||||
items.push({ ...opener, depth: depth + 1, kind: 'item', node: item, path: [...path, 'content', index], tag: 'li' })
|
||||
}
|
||||
return containerPieces('ul', ` class="${taskLists[type].listClass}"${attributes}`, node.content === undefined ? undefined : items)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user