Read the emphasis, the links and the lone image CommonMark spells (#34)
CI / gate (push) Successful in 5s

This commit was merged in pull request #34.
This commit is contained in:
2026-08-31 22:33:54 +02:00
parent 0476d33b7b
commit 4ad80e79c5
31 changed files with 899 additions and 218 deletions
+32
View File
@@ -0,0 +1,32 @@
import type { AdfMark, AdfNode } from './document.ts'
import { serializeCanonicalJson } from '../canonical-json.ts'
export function sameMark(candidate: AdfMark, mark: AdfMark): boolean {
return markKey(candidate) === markKey(mark)
}
// AGENTS.md §2: adjacent text nodes carrying identical marks are one node.
export function mergeAdjacentText(nodes: readonly AdfNode[]): AdfNode[] {
const merged: AdfNode[] = []
for (const node of nodes) {
const previous = merged[merged.length - 1]
if (previous !== undefined && previous.type === 'text' && node.type === 'text' && sameMarks(previous, node)) {
merged[merged.length - 1] = { ...previous, text: `${previous.text ?? ''}${node.text ?? ''}` }
continue
}
merged.push(node)
}
return merged
}
function sameMarks(previous: AdfNode, node: AdfNode): boolean {
return marksKey(previous.marks ?? []) === marksKey(node.marks ?? [])
}
function marksKey(marks: readonly AdfMark[]): string {
return marks.map(markKey).join('\n')
}
function markKey(mark: AdfMark): string {
return `${mark.type} ${serializeCanonicalJson(mark.attrs ?? {}, 'compact')}`
}