32 - a mark's attribute depth is counted from its value, the marks spelling refusing its own
This commit is contained in:
@@ -68,9 +68,9 @@ test('names the attribute nesting past the levels the parser reads one at, and s
|
||||
assert.equal(faultCode(withAttribute(nested(largestNesting + 1))), 'unsupported-nesting-depth')
|
||||
assert.equal(isAdfDocument(withAttribute(nested(largestNesting + 1))), true)
|
||||
const marked = (levels: number): unknown => ({ content: [{ marks: [{ attrs: { a: nested(levels) }, type: 'link' }], text: 'x', type: 'text' }], type: 'doc', version: 1 })
|
||||
assert.equal(fault(marked(largestNesting - 3)), 'accepted')
|
||||
assert.equal(fault(marked(largestNesting - 2)), deeper('a', 'link', largestNesting - 3))
|
||||
assert.equal(isAdfDocument(marked(largestNesting - 2)), true)
|
||||
assert.equal(fault(marked(largestNesting)), 'accepted')
|
||||
assert.equal(fault(marked(largestNesting + 1)), deeper('a', 'link'))
|
||||
assert.equal(isAdfDocument(marked(largestNesting + 1)), true)
|
||||
})
|
||||
|
||||
test('accepts the JSON values an attribute may hold', () => {
|
||||
|
||||
+5
-8
@@ -23,9 +23,6 @@ export type AdfDocument = {
|
||||
version: number
|
||||
}
|
||||
|
||||
// A block directive spells the whole mark set as one JSON attribute, so a mark's value sits three levels inside it.
|
||||
const markAttributeNesting = largestNesting - 3
|
||||
|
||||
const documentKeys = ['content', 'type', 'version']
|
||||
const markKeys = ['attrs', 'type']
|
||||
const nodeKeys = ['attrs', 'content', 'marks', 'text', 'type']
|
||||
@@ -47,8 +44,8 @@ export function adfDocumentFault(value: unknown): ConvertFault | undefined {
|
||||
return nestingFault(content)
|
||||
}
|
||||
|
||||
export function attributeNestingMessage(key: string, type: string, levels: number = largestNesting): string {
|
||||
return `the ${key} attribute of ${type} nests deeper than the ${levels} levels an attribute carries`
|
||||
export function attributeNestingMessage(key: string, type: string): string {
|
||||
return `the ${key} attribute of ${type} nests deeper than the ${largestNesting} levels an attribute carries`
|
||||
}
|
||||
|
||||
export function carriesOnly(node: AdfNode, attributes: readonly string[]): boolean {
|
||||
@@ -116,15 +113,15 @@ function nestingFault(nodes: readonly AdfNode[]): ConvertFault | undefined {
|
||||
|
||||
function marksFault(marks: readonly AdfMark[]): ConvertFault | undefined {
|
||||
for (const mark of marks) {
|
||||
const fault = attributesFault(nodeAttrs(mark), mark.type, markAttributeNesting)
|
||||
const fault = attributesFault(nodeAttrs(mark), mark.type)
|
||||
if (fault !== undefined) return fault
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
function attributesFault(attrs: AdfAttributes, type: string, levels: number = largestNesting): ConvertFault | undefined {
|
||||
function attributesFault(attrs: AdfAttributes, type: string): ConvertFault | undefined {
|
||||
for (const [key, value] of Object.entries(attrs)) {
|
||||
if (overNested(value, levels)) return { code: 'unsupported-nesting-depth', message: attributeNestingMessage(key, type, levels) }
|
||||
if (overNested(value)) return { code: 'unsupported-nesting-depth', message: attributeNestingMessage(key, type) }
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user