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

Group a line's runs in one home, part a line as its first fallback, and trim each portable line by its own runs

This commit is contained in:
2026-11-03 23:36:47 +01:00
committed by Lillem4n
parent d15d063c43
commit bab2ffcfb8
13 changed files with 222 additions and 189 deletions
@@ -927,6 +927,15 @@ test('spells an emphasis or link run once across the hard breaks between two nod
assert.equal(readsBack(document(paragraph({ text: 'x', type: 'text' }, marked('.', em), hardBreak, marked('b', em)))), 'x!adf:carry{json="{\\"marks\\":[{\\"type\\":\\"em\\"}],\\"text\\":\\".\\",\\"type\\":\\"text\\"}"}\\\n_b_\n')
})
test('parts every run on a line that needs a fallback, whichever run needs it', () => {
const em: AdfMark = { type: 'em' }
const marked = (text: string, ...marks: AdfMark[]): AdfNode => ({ marks, text, type: 'text' })
assert.equal(
readsBack(document(paragraph({ text: 'x', type: 'text' }, marked('.', { type: 'strong' }), { text: 'y ', type: 'text' }, marked('a', em), { type: 'hardBreak' }, marked('b', em)))),
'x!adf:carry{json="{\\"marks\\":[{\\"type\\":\\"strong\\"}],\\"text\\":\\".\\",\\"type\\":\\"text\\"}"}y _a_\\\n_b_\n',
)
})
test('spells an emphasis run once across the code spans, mentions, dates and inline media between two nodes holding the mark', () => {
const strong: AdfMark = { type: 'strong' }
const marked = (text: string, ...marks: AdfMark[]): AdfNode => ({ marks, text, type: 'text' })
+32 -107
View File
@@ -1,13 +1,14 @@
import type { AdfMark, AdfNode } from '../../adf/document.ts'
import type { InlineNodeModel } from '../../adf/inline-nodes.ts'
import type { InlineRun, RunGrouping, RunNode } from './inline-runs.ts'
import type { LineContainer } from '../line-container.ts'
import type { LinkDefinition, TitleEscapes } from '../commonmark/link-syntax.ts'
import type { RunFallback } from './unspellable-runs.ts'
import type { WrittenFlavour } from '../flavour.ts'
import { assembleInlineLine, isSyntax, type InlineEscaping, type InlineSegment, type MarkRun, type NodeRange } from './line-escaping.ts'
import { carriedInline } from '../opaque-carry.ts'
import { commonMarkLink, insideRun, isEmphasis, linkHref, markSpelling, runSpans, spellMarkAttributes, type RunNode } from '../mark-spellings.ts'
import { directivePrefix, slotFault, spellInlineDirectiveOpener, spellInlineLeafDirective } from '../directive/syntax.ts'
import { carries, inlineRuns } from './inline-runs.ts'
import { commonMarkLink, isEmphasis, linkHref, markSpelling, spellMarkAttributes } from '../mark-spellings.ts'
import { escapeUnbalanced, spellDestination, spellLinkTarget } from '../commonmark/link-syntax.ts'
import { failure, success, type ConvertErrorPath, type Result } from '../../result.ts'
import { flavourClaims } from '../flavour.ts'
@@ -18,6 +19,7 @@ import { isSpellableText, nodeAttrs, nodeContent, nodeMarks } from '../../adf/do
import { joinsWhenRead, textBreakSpelling } from '../adjacent-text.ts'
import { largestNesting } from '../../nesting.ts'
import { longestBacktickRun } from '../commonmark/backtick-runs.ts'
import { slotFault, spellInlineDirectiveOpener, spellInlineLeafDirective } from '../directive/syntax.ts'
import { spellInlineNodeAttributes } from '../directive/inline-spelling.ts'
import { spellTextDirective } from '../directive/text.ts'
@@ -28,26 +30,20 @@ type Emission = { carries: [NodeRange, ...NodeRange[]]; segments?: undefined } |
type Fallback = [NodeRange, ...NodeRange[]] | 'opening-link'
type InlineContext = {
type InlineContext = RunGrouping & {
atBlockEnd: boolean
bracketed: boolean
carried: ReadonlySet<number>
container: LineContainer
flavour: WrittenFlavour
lineNodes: readonly AdfNode[]
openingLinkAsDirective: boolean
path: ConvertErrorPath
spans: boolean
spansLines: boolean
}
type InlineRun = { index: number; kind: 'marked'; mark: AdfMark; nodes: RunNode[] } | { index: number; kind: 'plain'; node: AdfNode }
type LineAttempt = { fallback: Fallback; line?: undefined; segments?: undefined } | { fallback?: undefined; line: string; segments: InlineSegment[] }
type LineFallbacks = { carried: Set<number>; flavour: WrittenFlavour; openingLinkAsDirective: boolean }
type RunGrouping = { carried: ReadonlySet<number>; spans: boolean }
type LineFallbacks = { carried: Set<number>; flavour: WrittenFlavour; openingLinkAsDirective: boolean; parted: boolean }
// docs/decisions.md §After 32 passes, a line carries or drops every em, strike and strong mark.
export const readBackPasses = 32
@@ -66,9 +62,9 @@ export function openingLinkTakesDirective(nodes: readonly AdfNode[], path: Conve
return success(emitted.value.openingLinkAsDirective)
}
export function portableLineFallback(nodes: readonly AdfNode[], container: LineContainer, path: ConvertErrorPath): Result<PortableLineFallback | undefined> {
const fallbacks = withheldMarkFallbacks(nodes, 'portable')
const emission = lineSegments(nodes, container, path, fallbacks, false)
export function portableLineFallback(nodes: readonly AdfNode[], container: LineContainer, path: ConvertErrorPath, { parted }: Pick<RunGrouping, 'parted'>): Result<PortableLineFallback | undefined> {
const fallbacks = { ...withheldMarkFallbacks(nodes, 'portable'), parted }
const emission = lineSegments(nodes, container, path, fallbacks)
if (!emission.ok) return emission
if (fallbacks.carried.size > 0 || emission.value.carries !== undefined) return failure('unsupported-node-shape', 'an inline node on a portable line has no spelling but the carry', path)
const verdict = lineVerdict(emission.value.segments, container, 'portable', { kind: 'drop', nodes })
@@ -97,8 +93,8 @@ export function tryImageLine(alt: string | undefined, url: string, flavour: Writ
function emitLine(nodes: readonly AdfNode[], container: LineContainer, path: ConvertErrorPath, flavour: WrittenFlavour): Result<EmittedLine> {
const fallbacks = withheldMarkFallbacks(nodes, flavour)
// Terminates because takeFallback refuses a pass that took no new fallback.
for (let pass = 1; ; pass += 1) {
// Terminates because takeFallback refuses a pass that took no new fallback. Pass 0 only parts the line, so `readBackPasses` counts what a parted line takes.
for (let pass = 0; ; pass += 1) {
const attempt = linePass(nodes, container, path, fallbacks)
if (!attempt.ok) return attempt
const { fallback, line, segments } = attempt.value
@@ -109,20 +105,8 @@ function emitLine(nodes: readonly AdfNode[], container: LineContainer, path: Con
}
}
// spec/flavour.md, Marks: a pass writes the spanned line where it needs no fallback; otherwise it writes the parted line and takes that line's fallbacks.
export function linePass(nodes: readonly AdfNode[], container: LineContainer, path: ConvertErrorPath, fallbacks: LineFallbacks): Result<LineAttempt> {
const spanned = lineAttempt(nodes, container, path, fallbacks, true)
return spanned.ok && writesSpanned(spanned.value, fallbacks.flavour) ? spanned : lineAttempt(nodes, container, path, fallbacks, false)
}
function writesSpanned({ fallback, segments }: LineAttempt, flavour: WrittenFlavour): boolean {
if (fallback !== undefined) return false
// A span can leave whitespace at a line edge, which only `!adf:text` spells.
return flavourClaims[flavour].directives || !segments.some((segment) => segment.escaping === 'none' && segment.text.startsWith(directivePrefix))
}
function lineAttempt(nodes: readonly AdfNode[], container: LineContainer, path: ConvertErrorPath, fallbacks: LineFallbacks, spans: boolean): Result<LineAttempt> {
const emission = lineSegments(nodes, container, path, fallbacks, spans)
const emission = lineSegments(nodes, container, path, fallbacks)
if (!emission.ok) return emission
const { carries, segments } = emission.value
return success(segments === undefined ? { fallback: carries } : attemptLine(segments, container, fallbacks.flavour))
@@ -139,10 +123,15 @@ export function withheldMarkFallbacks(nodes: readonly AdfNode[], flavour: Writte
const taken = takenMarkTypes(node)
if (taken !== undefined && nodeMarks(node).some((mark) => !taken.includes(mark.type))) carried.add(index)
}
return { carried, flavour, openingLinkAsDirective: false }
return { carried, flavour, openingLinkAsDirective: false, parted: false }
}
export function takeFallback(fallbacks: LineFallbacks, fallback: Fallback, path: ConvertErrorPath): Result<null> {
// spec/flavour.md, Marks: a line needing a fallback first parts its runs, and takes what the parted line still needs.
if (!fallbacks.parted) {
fallbacks.parted = true
return success(null)
}
if (fallback === 'opening-link') {
if (fallbacks.openingLinkAsDirective) return failure('unsupported-node-shape', 'an opening link spelled as a directive still reads as a link definition, so the line has no spelling left', path)
fallbacks.openingLinkAsDirective = true
@@ -154,12 +143,12 @@ export function takeFallback(fallbacks: LineFallbacks, fallback: Fallback, path:
return success(null)
}
function lineSegments(nodes: readonly AdfNode[], container: LineContainer, path: ConvertErrorPath, fallbacks: LineFallbacks, spans: boolean): Result<Emission> {
const context: InlineContext = { atBlockEnd: true, bracketed: false, ...fallbacks, container, lineNodes: nodes, path, spans, spansLines: container === 'paragraph' }
function lineSegments(nodes: readonly AdfNode[], container: LineContainer, path: ConvertErrorPath, fallbacks: LineFallbacks): Result<Emission> {
const context: InlineContext = { atBlockEnd: true, bracketed: false, ...fallbacks, container, lineNodes: nodes, path, spansLines: container === 'paragraph' }
const emission = emitRun(nodes.map((node) => ({ node, outer: 0 })), 0, 0, context)
if (!emission.ok) return emission
if (emission.value.carries !== undefined) return emission
return success({ segments: spellEdgeWhitespace(emission.value.segments) })
return success({ segments: spellEdgeWhitespace(emission.value.segments, fallbacks.flavour) })
}
function attemptLine(segments: InlineSegment[], container: LineContainer, flavour: WrittenFlavour): LineAttempt {
@@ -177,8 +166,9 @@ function lineVerdict(segments: readonly InlineSegment[], container: LineContaine
return run === undefined ? { kind: 'line', text: assembled.line } : { kind: 'unspellable-run', runs: [run, ...others] }
}
// A space or tab CommonMark strips at a line edge rides !adf:text{text="…"}.
function spellEdgeWhitespace(segments: readonly InlineSegment[]): InlineSegment[] {
// A space or tab CommonMark strips at a line edge rides !adf:text{text="…"}. A flavour without directives leaves it raw, since the reducer trims each line by its own runs.
function spellEdgeWhitespace(segments: InlineSegment[], flavour: WrittenFlavour): InlineSegment[] {
if (!flavourClaims[flavour].directives) return segments
const spelled: InlineSegment[] = []
for (const [index, segment] of segments.entries()) {
const previous = segments[index - 1]
@@ -244,56 +234,6 @@ function emitRun(nodes: readonly RunNode[], depth: number, firstIndex: number, c
return success(carry === undefined ? { segments } : { carries: [carry, ...others] })
}
function inlineRuns(nodes: readonly RunNode[], firstIndex: number, grouping: RunGrouping): InlineRun[] {
const runs: InlineRun[] = []
let next = 0
for (const [offset, { node, outer }] of nodes.entries()) {
if (offset < next) continue
const index = firstIndex + offset
// A carried node spells its marks inside the carry.
const mark = carries(node, grouping.carried, index) ? undefined : nodeMarks(node)[outer]
if (mark === undefined) {
runs.push({ index, kind: 'plain', node })
continue
}
const inside = nodesInRun(nodes, offset, mark, firstIndex, grouping)
runs.push({ index, kind: 'marked', mark, nodes: inside })
next = offset + inside.length
}
return runs
}
// The run of `mark` opening at `first` ends at the last node holding the mark, so the nodes it spans past that one stay outside.
function nodesInRun(nodes: readonly RunNode[], first: number, mark: AdfMark, firstIndex: number, { carried, spans }: RunGrouping): RunNode[] {
const inside: RunNode[] = []
let holders = 0
for (let offset = first; offset < nodes.length; offset += 1) {
const runNode = nodes[offset]
if (runNode === undefined || carries(runNode.node, carried, firstIndex + offset)) break
const held = insideRun(runNode, mark)
if (held === undefined && !(spans && runSpans(runNode.node, mark))) break
inside.push(held ?? runNode)
if (held !== undefined) holders = inside.length
}
return inside.slice(0, holders)
}
// For each leaf but the last, how many runs of the spanned line hold both it and the next leaf.
export function runsSharedWithNext(leaves: readonly AdfNode[]): number[] {
const shared = leaves.map(() => 0)
countSharedRuns(leaves.map((node) => ({ node, outer: 0 })), 0, 0, shared)
return shared
}
function countSharedRuns(nodes: readonly RunNode[], depth: number, firstIndex: number, shared: number[]): void {
if (depth > largestNesting) return
for (const run of inlineRuns(nodes, firstIndex, { carried: new Set(), spans: true })) {
if (run.kind === 'plain') continue
for (let index = run.index; index < run.index + run.nodes.length - 1; index += 1) shared[index] = (shared[index] ?? 0) + 1
countSharedRuns(run.nodes, depth + 1, run.index, shared)
}
}
function takesTextBreak(previous: InlineRun | undefined, run: InlineRun, carried: ReadonlySet<number>): boolean {
if (previous?.kind !== 'plain' || run.kind !== 'plain') return false
if (carries(previous.node, carried, previous.index) || carries(run.node, carried, run.index)) return false
@@ -304,16 +244,6 @@ function nodePath(context: InlineContext, index: number): ConvertErrorPath {
return [...context.path, 'content', index]
}
// Decides the text-node and slot-fault carries up front, `withheldMarkFallbacks` the withheld-mark ones, so a line holding many of them is emitted once.
function carries(node: AdfNode, carried: ReadonlySet<number>, index: number): boolean {
if (carried.has(index)) return true
if (node.type === 'text') return !isSpellableText(node) || typeof node.text !== 'string' || node.text === ''
const model = inlineNodeModel(node.type)
if (model === undefined) return true
const slot = model.textAttribute === undefined ? undefined : nodeAttrs(node)[model.textAttribute]
return typeof slot === 'string' && slotFault(node.type, slot) !== undefined && nodeContent(node).length === 0 && node.text === undefined
}
// Builds the node's path only to refuse it: a path copies every level above, and a line may hold a million leaves.
function emitLeaf(node: AdfNode, context: InlineContext, index: number): Result<Emission> {
if (carries(node, context.carried, index)) {
@@ -366,7 +296,7 @@ function textSegments(node: AdfNode, context: InlineContext): InlineSegment[] |
function emitMarkedRun(nodes: readonly RunNode[], mark: AdfMark, depth: number, index: number, context: InlineContext): Result<Emission> {
const range: NodeRange = { first: index, last: index + nodes.length - 1 }
if (mark.type === 'backgroundColor' && flavourClaims[context.flavour].highlights) return emitHighlight(nodes, depth, range, context)
if (mark.type === 'backgroundColor' && flavourClaims[context.flavour].highlights) return emitHighlight(nodes, depth, { ...range, mark }, context)
const spelling = markSpelling(mark.type)
const attributes = spelling === undefined ? undefined : spellMarkAttributes(mark, spelling)
if (spelling === undefined || attributes === undefined) return carriedRun(range, context)
@@ -374,7 +304,7 @@ function emitMarkedRun(nodes: readonly RunNode[], mark: AdfMark, depth: number,
const spans = codeSpans(nodes)
return spans === undefined ? carriedRun(range, context) : success({ segments: [syntax(spans)] })
}
if (spelling.kind === 'emphasis') return emitEmphasis(nodes, spelling.spelling, depth, range, context)
if (spelling.kind === 'emphasis') return emitEmphasis(nodes, spelling.spelling, depth, { ...range, mark }, context)
const link = spelling.kind === 'link' ? tryLink(nodes, mark, depth, range, context) : undefined
if (link !== undefined) return link
const inner = emitRun(nodes, depth + 1, index, { ...context, bracketed: true, spansLines: false })
@@ -383,24 +313,19 @@ function emitMarkedRun(nodes: readonly RunNode[], mark: AdfMark, depth: number,
return success({ segments: [syntax(spellInlineDirectiveOpener(mark.type)), ...inner.value.segments, syntax(`]${attributes}`)] })
}
function emitEmphasis(nodes: readonly RunNode[], spelling: string, depth: number, range: NodeRange, context: InlineContext): Result<Emission> {
const inner = emitRun(nodes, depth + 1, range.first, context)
function emitEmphasis(nodes: readonly RunNode[], spelling: string, depth: number, run: MarkRun, context: InlineContext): Result<Emission> {
const inner = emitRun(nodes, depth + 1, run.first, context)
if (!inner.ok) return inner
if (inner.value.carries !== undefined) return inner
const spelled = spellEdgeWhitespace(inner.value.segments)
const spelled = spellEdgeWhitespace(inner.value.segments, context.flavour)
return success({
segments: [
{ emphasis: 'open', escaping: 'none', nodes: { ...range, depth }, text: spelling },
...spelled,
{ emphasis: 'close', escaping: 'none', nodes: { ...range, depth }, text: spelling },
],
segments: [{ emphasis: 'open', escaping: 'none', nodes: run, text: spelling }, ...spelled, { emphasis: 'close', escaping: 'none', nodes: run, text: spelling }],
})
}
function emitHighlight(nodes: readonly RunNode[], depth: number, range: NodeRange, context: InlineContext): Result<Emission> {
const inner = emitRun(nodes, depth + 1, range.first, context)
function emitHighlight(nodes: readonly RunNode[], depth: number, run: MarkRun, context: InlineContext): Result<Emission> {
const inner = emitRun(nodes, depth + 1, run.first, context)
if (!inner.ok || inner.value.carries !== undefined) return inner
const run = { ...range, depth }
return success({
segments: [{ escaping: 'none', highlight: 'open', nodes: run, text: highlightDelimiter }, ...inner.value.segments, { escaping: 'none', highlight: 'close', nodes: run, text: highlightDelimiter }],
})
+68
View File
@@ -0,0 +1,68 @@
import type { AdfMark, AdfNode } from '../../adf/document.ts'
import { identicalMark, isSpellableText, nodeAttrs, nodeContent, nodeMarks } from '../../adf/document.ts'
import { inlineNodeModel, takesMark } from '../../adf/inline-nodes.ts'
import { markSpelling } from '../mark-spellings.ts'
import { slotFault } from '../directive/syntax.ts'
export type InlineRun = { index: number; kind: 'marked'; mark: AdfMark; nodes: RunNode[] } | { index: number; kind: 'plain'; node: AdfNode }
// `parted` keeps a run from crossing any node.
export type RunGrouping = { carried: ReadonlySet<number>; parted: boolean }
// An inline node inside the runs of its first `outer` marks. A node a run crosses holds no mark of that run, so its `outer` stays.
export type RunNode = { node: AdfNode; outer: number }
export const partedLine: RunGrouping = { carried: new Set(), parted: true }
export const spannedLine: RunGrouping = { carried: new Set(), parted: false }
// spec/flavour.md, Marks. The portable reducer must ask this too, or it trims edge whitespace by runs the writers do not spell.
export function inlineRuns(nodes: readonly RunNode[], firstIndex: number, grouping: RunGrouping): InlineRun[] {
const runs: InlineRun[] = []
let end = 0
for (const [offset, { node, outer }] of nodes.entries()) {
if (offset < end) continue
const index = firstIndex + offset
// A carried node spells its marks inside the carry.
const mark = carries(node, grouping.carried, index) ? undefined : nodeMarks(node)[outer]
if (mark === undefined) {
runs.push({ index, kind: 'plain', node })
continue
}
end = runEnd(nodes, offset, mark, firstIndex, grouping)
runs.push({ index, kind: 'marked', mark, nodes: nodes.slice(offset, end).map((runNode) => insideRun(runNode, mark) ?? runNode) })
}
return runs
}
// A run opens and closes at a node holding its mark, so a node it would cross past the last such node stays outside.
function runEnd(nodes: readonly RunNode[], first: number, mark: AdfMark, firstIndex: number, { carried, parted }: RunGrouping): number {
let end = first + 1
for (let offset = end; offset < nodes.length; offset += 1) {
const runNode = nodes[offset]
if (runNode === undefined || carries(runNode.node, carried, firstIndex + offset)) break
if (insideRun(runNode, mark) !== undefined) end = offset + 1
else if (parted || !runCrosses(runNode.node, mark)) break
}
return end
}
export function insideRun({ node, outer }: RunNode, mark: AdfMark): RunNode | undefined {
const held = nodeMarks(node)[outer]
return held !== undefined && identicalMark(held, mark) ? { node, outer: outer + 1 } : undefined
}
// The readers refuse `marks=empty` inside a mark's spelling.
function runCrosses(node: AdfNode, mark: AdfMark): boolean {
const kind = markSpelling(mark.type)?.kind
return (kind === 'emphasis' || kind === 'link') && !takesMark(node, mark.type) && node.marks?.length !== 0
}
// Decides the text-node and slot-fault carries up front, `withheldMarkFallbacks` the withheld-mark ones, so a line holding many of them is emitted once.
export function carries(node: AdfNode, carried: ReadonlySet<number>, index: number): boolean {
if (carried.has(index)) return true
if (node.type === 'text') return !isSpellableText(node) || typeof node.text !== 'string' || node.text === ''
const model = inlineNodeModel(node.type)
if (model === undefined) return true
const slot = model.textAttribute === undefined ? undefined : nodeAttrs(node)[model.textAttribute]
return typeof slot === 'string' && slotFault(node.type, slot) !== undefined && nodeContent(node).length === 0 && node.text === undefined
}
+2 -2
View File
@@ -1,3 +1,4 @@
import type { AdfMark } from '../../adf/document.ts'
import type { Claims, WrittenFlavour } from '../flavour.ts'
import type { InlineReading } from '../inline-content.ts'
import type { InlineSource, InlineToken } from '../inline-tokens.ts'
@@ -19,8 +20,7 @@ export type InlineEscaping = (typeof escapingCodes)[number]
export type NodeRange = { first: number; last: number }
// `depth` is the run's nesting level. On a parted line, the only line a fallback reads, that is the index into each node's marks array that the run spells.
export type MarkRun = NodeRange & { depth: number }
export type MarkRun = NodeRange & { mark: AdfMark }
export type InlineSegment =
| { emphasis: DelimiterRole; escaping: 'none'; highlight?: undefined; nodes: MarkRun; text: string }
+7 -8
View File
@@ -1,9 +1,9 @@
import type { AdfNode } from '../../adf/document.ts'
import type { AdfMark, AdfNode } from '../../adf/document.ts'
import type { DelimiterRole, MarkRun, PlacedSegment } from './line-escaping.ts'
import type { InlineReading } from '../inline-content.ts'
import { delimiterFlags, isWordCharacter } from '../commonmark/emphasis-matching.ts'
import { highlightFlanking } from '../inline-tokens.ts'
import { nodeMarks } from '../../adf/document.ts'
import { identicalMark, nodeMarks } from '../../adf/document.ts'
// How the caller takes a run back: a carry swaps its nodes for one carry directive, splitting every run holding it; a drop removes its mark from the line's `nodes`.
export type RunFallback = { kind: 'carry' } | { kind: 'drop'; nodes: readonly AdfNode[] }
@@ -88,14 +88,13 @@ function mergingEnds(pairs: readonly EmphasisPair[], fallback: RunFallback): Set
// Dropping the run merges no runs and moves no run's end, whatever else drops: at each end, the node outside holds no mark type the end node holds inside the run's mark.
function dropsAlone(nodes: readonly AdfNode[], run: MarkRun): boolean {
return endsAlone(nodes[run.first], nodes[run.first - 1], run.depth) && endsAlone(nodes[run.last], nodes[run.last + 1], run.depth)
return endsAlone(nodes[run.first], nodes[run.first - 1], run.mark) && endsAlone(nodes[run.last], nodes[run.last + 1], run.mark)
}
function endsAlone(edge: AdfNode | undefined, beside: AdfNode | undefined, depth: number): boolean {
const besideTypes = new Set(nodeMarks(beside ?? {}).map((mark) => mark.type))
return nodeMarks(edge ?? {})
.slice(depth + 1)
.every((mark) => !besideTypes.has(mark.type))
function endsAlone(edge: AdfNode | undefined, beside: AdfNode | undefined, mark: AdfMark): boolean {
const besideTypes = new Set(nodeMarks(beside ?? {}).map((held) => held.type))
const marks = nodeMarks(edge ?? {})
return marks.slice(marks.findIndex((held) => identicalMark(held, mark)) + 1).every((held) => !besideTypes.has(held.type))
}
// A pair falls with the first only where that leaves the line as the one-run-per-pass reference writes it: it falls cleanly, and cannot read whichever character it is written with.