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

Answer architecture round 1: 1 🔴, 2 🟡; read a node's taken mark types once, let the highlight ask takesMark, correct the README's code-span bullet

This commit is contained in:
2026-10-14 20:42:33 +02:00
committed by Lillem4n
parent 31f01f2fc0
commit c9f9276df9
7 changed files with 20 additions and 14 deletions
+8 -4
View File
@@ -37,8 +37,12 @@ export function inlineNodeModel(type: string): InlineNodeModel | undefined {
return Object.hasOwn(inlineNodes, type) ? inlineNodes[type] : undefined
}
// The table withholds nothing from a type it does not list, such as text; Atlassian's schema withholds from code text all but `codeTextMarkTypes`.
export function takesMark(node: AdfNode, markType: string): boolean {
if (node.type === 'text' && nodeMarks(node).some((mark) => mark.type === 'code')) return codeTextMarkTypes.includes(markType)
return inlineNodeModel(node.type)?.markTypes.includes(markType) ?? true
// Undefined where the schema withholds no mark: the table lists no such type, text among them, but code text takes only `codeTextMarkTypes`.
export function takenMarkTypes(node: AdfNode): readonly string[] | undefined {
if (node.type === 'text') return nodeMarks(node).some((mark) => mark.type === 'code') ? codeTextMarkTypes : undefined
return inlineNodeModel(node.type)?.markTypes
}
export function takesMark(node: AdfNode, markType: string): boolean {
return takenMarkTypes(node)?.includes(markType) ?? true
}