diff --git a/src/html/alignment-element.ts b/src/html/alignment-element.ts index 12877ef..f5b598a 100644 --- a/src/html/alignment-element.ts +++ b/src/html/alignment-element.ts @@ -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) diff --git a/src/html/emit/adf-to-html.test.ts b/src/html/emit/adf-to-html.test.ts index d0d42b2..0905652 100644 --- a/src/html/emit/adf-to-html.test.ts +++ b/src/html/emit/adf-to-html.test.ts @@ -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', () => { diff --git a/src/html/emit/adf-to-html.ts b/src/html/emit/adf-to-html.ts index 99b0012..4ebf3a7 100644 --- a/src/html/emit/adf-to-html.ts +++ b/src/html/emit/adf-to-html.ts @@ -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 `