3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-20 07:05:44 +01:00

Answer prose round 3: the comments on highlight pairing, escaped backtick lengths and the memo read once, and the Raw HTML paragraph loses its half clause

This commit is contained in:
2026-10-04 23:03:11 +02:00
committed by Lillem4n
parent 1ff27164f8
commit 1b55e0f528
4 changed files with 7 additions and 7 deletions
+3 -3
View File
@@ -195,9 +195,9 @@ is the fence.
## Raw HTML in input
CommonMark input may contain raw HTML. `markdownToAdf` routes each construct through the foreign
HTML element mapping (`docs/decisions.md` §Foreign HTML sorts three ways; specified with the HTML
dialect) — ADF has no raw-HTML node, so a construct without a mapping, comments and processing
instructions included, is an error result naming it. The flavour never emits raw HTML.
HTML element mapping (`docs/decisions.md` §Foreign HTML sorts three ways) — ADF has no raw-HTML
node, so a construct without a mapping, comments and processing instructions included, is an error
result naming it. The flavour never emits raw HTML.
## Block nodes
+1 -1
View File
@@ -114,7 +114,7 @@ function readableBlock(node: AdfNode, path: ConvertErrorPath, depth: number, wri
const kept = memo?.get(node)
if (kept !== undefined) {
if (kept.block === undefined) return undefined
// An entry holds the spelling at its fill depth: a read at or above it rebases headroom, a read below re-spells, since a hit skips the depth guards the walk runs.
// An entry holds the spelling at its fill depth. A read at or above it rebases headroom; a read below re-spells, because a hit skips the walk's depth guards.
if (depth <= kept.depth) return success({ ...kept.block, headroom: kept.block.headroom + kept.depth - depth })
}
const spelled = spellReadableBlock(node, path, depth, writing)
+2 -2
View File
@@ -121,10 +121,10 @@ function claimsHighlight(scan: string, index: number): boolean {
return flanking.opens || flanking.closes
}
// CommonMark reads no escape inside a code span, so a backtick string an escape forms or splits off still closes one an earlier bare run opens.
// CommonMark reads no escape inside a code span, so a backtick string left beside an escape still closes a span that an earlier bare run of its length opens.
function escapeClosedRuns(scan: string, escapings: readonly InlineEscaping[], claimed: ReadonlySet<number>): ReadonlySet<number> {
const escaped = new Set(claimed)
// The lengths of the backtick strings an escape forms or splits off: a bare run that long closes the span one opens.
// The lengths of the backtick strings escapes leave: a bare run of one of these lengths would open a span one of them closes, so it is escaped too.
const formed = new Set<number>()
let end = scan.length - 1
while (end >= 0) {
+1 -1
View File
@@ -605,7 +605,7 @@ function highlightDelimiters(pieces: readonly Piece[], nodes: readonly Inline[][
return found
}
// Each opener takes the next closer holding at least one character after it, both in one stretch and under the same marks.
// Each opener pairs with the next closer at least one character after it, and only when both sit in one stretch under the same marks.
function pairedHighlights(pieces: readonly Piece[], nodes: readonly Inline[][]): { closer: number; opener: number }[] {
const found = highlightDelimiters(pieces, nodes)
const paired: { closer: number; opener: number }[] = []