10a - adfToPlainMarkdown's ADF→ADF reduction #128

Merged
lilleman merged 20 commits from 10a into main 2026-09-25 19:42:37 +02:00
Showing only changes of commit 687ba9bf90 - Show all commits
-3
View File
@@ -98,7 +98,6 @@ export function oneLine(text: string): string {
return text.replace(/[\r\u0000]/g, '').replace(/\n/g, ' ') return text.replace(/[\r\u0000]/g, '').replace(/\n/g, ' ')
} }
// Blank once a text leaf's cleaning has run is empty.
function nonEmpty(value: unknown): string | undefined { function nonEmpty(value: unknown): string | undefined {
return typeof value === 'string' && oneLine(value).trim() !== '' ? value : undefined return typeof value === 'string' && oneLine(value).trim() !== '' ? value : undefined
} }
@@ -115,7 +114,6 @@ function lineBreak(container: LineContainer): AdfNode {
return container === 'paragraph' ? { type: 'hardBreak' } : textLeaf(' ', []) return container === 'paragraph' ? { type: 'hardBreak' } : textLeaf(' ', [])
} }
// note: what the content is named in the note left where it has none.
function textLeaves(value: unknown, marks: readonly AdfMark[], container: LineContainer, note?: string): AdfNode[] { function textLeaves(value: unknown, marks: readonly AdfMark[], container: LineContainer, note?: string): AdfNode[] {
if (typeof value !== 'string') return note === undefined ? [] : noteLeaves(note) if (typeof value !== 'string') return note === undefined ? [] : noteLeaves(note)
const text = value.replace(/[\r\u0000]/g, '') const text = value.replace(/[\r\u0000]/g, '')
@@ -235,7 +233,6 @@ function leafEdges(leaf: AdfNode, previous: AdfNode | undefined, next: AdfNode |
return edges return edges
} }
// The marks the whitespace keeps, or undefined where it goes.
function edgeDepth(marks: readonly AdfMark[], neighbour: AdfNode | undefined, whitespace: string): number | undefined { function edgeDepth(marks: readonly AdfMark[], neighbour: AdfNode | undefined, whitespace: string): number | undefined {
if (whitespace === '') return marks.length if (whitespace === '') return marks.length
const lineEdge = neighbour === undefined || neighbour.type === 'hardBreak' const lineEdge = neighbour === undefined || neighbour.type === 'hardBreak'