3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-21 15:42:58 +01:00

Keep BlockText's measures as two named records, read its flags through two functions, and claim a marker through one guard

This commit is contained in:
2026-10-30 21:53:59 +01:00
committed by Lillem4n
parent d28bb4a13f
commit 7941972471
6 changed files with 88 additions and 59 deletions
+7 -2
View File
@@ -12,8 +12,8 @@ import { nodeAttrs, nodeContent } from '../../adf/document.ts'
const portableBlockWriters: FlavourBlockWriters = {
// GitHub reads a task marker opening any item's first paragraph as a checkbox, whatever its siblings hold.
claimsItem: (text) => text.firstCharacter === markerOpening && leadingMarker(opening(text), readTaskMarker) !== undefined,
claimsQuote: (text) => text.firstCharacter === markerOpening && leadingMarker(opening(text), readAlertMarker) !== undefined,
claimsItem: (text) => leadsWithMarker(text, readTaskMarker),
claimsQuote: (text) => leadsWithMarker(text, readAlertMarker),
spell: spellPortableBlock,
}
@@ -30,6 +30,11 @@ function spellPortableBlock(node: AdfNode, path: ConvertErrorPath, depth: number
return line.ok ? quotedBlocks(node, path, depth, writing, headed(`${foldedAlertMarker} ${line.value}`)) : line
}
// Reading a concatenated line copies it whole, so the first character is checked before the line is read.
function leadsWithMarker(text: BlockText, read: (text: string) => { length: number } | undefined): boolean {
return text.first.character === markerOpening && leadingMarker(opening(text), read) !== undefined
}
function headed(head: string): (body: BlockText) => BlockText {
return (body) => (body.length === 0 ? blockText(head) : joinedText([blockText(head), emptyLine, body]))
}