mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-19 06:35:44 +01:00
Answer prose round 1: 0 🔴, 14 🟡 (0 misread); correct comments that misstated the code, fix item 174's figures and tagline, retitle item 173
This commit is contained in:
@@ -35,7 +35,7 @@ export type PlacedBlocks = { blocks: readonly PlacedBlock[]; headroom: number }
|
||||
// CommonMark starts a new list where the marker changes, so every second list in a run of one kind takes `alternateText`.
|
||||
type SpelledBlock = { spelling: 'commonmark' | 'directive'; text: BlockText } | { alternateText: BlockText; interruptsParagraph: boolean; ordered: boolean; spelling: 'list'; text: BlockText }
|
||||
type Spell = () => Result<EmittedBlock> | undefined
|
||||
// ask: spell the node, keeping the spelling unless refused; take: spell the node, reading and dropping what is kept.
|
||||
// take: read and drop the node's kept spelling, else spell it; ask: as take, keeping a fresh spelling unless refused.
|
||||
export type SpellingMemo = Readonly<Record<'ask' | 'take', (node: AdfNode, depth: number, spell: Spell) => Result<EmittedBlock> | undefined>>
|
||||
type WalkedItem = { node: AdfNode; walk: PlacedBlocks }
|
||||
export type WrittenAs = { flavour: 'lossless' } | { blocks: FlavourBlockWriters; flavour: 'portable' }
|
||||
|
||||
@@ -30,7 +30,7 @@ type Emission = { carries: [NodeRange, ...NodeRange[]]; segments?: undefined } |
|
||||
|
||||
type Fallback = [NodeRange, ...NodeRange[]] | 'opening-link'
|
||||
|
||||
// How a line is judged and what its fallbacks do: the lossless writer carries nodes, the portable reduction drops marks.
|
||||
// How a line is judged and what its fallbacks do: the writer carries nodes, the portable reduction drops marks.
|
||||
export type FallbackAction<Line, LineFallback, Written> = {
|
||||
giveUpEmphasis: (line: Line) => Line
|
||||
judge: (line: Line, grouping: RunGrouping) => Result<LineJudgement<Line, LineFallback, Written>>
|
||||
@@ -118,7 +118,7 @@ function emitLine(nodes: readonly AdfNode[], container: LineContainer, path: Con
|
||||
|
||||
// spec/flavour.md, Marks: the spanned line where it reads back, else the parted line, taking one fallback a pass.
|
||||
export function settledLine<Line, LineFallback, Written>(line: Line, action: FallbackAction<Line, LineFallback, Written>): Result<Written> {
|
||||
// Terminates because `take` refuses a pass that changes nothing.
|
||||
// Terminates while each `take` refuses or moves one way: the writer carries more nodes, the reduction keeps fewer marks.
|
||||
for (let current = line, pass = 1; ; pass += 1) {
|
||||
let parting = current
|
||||
if (pass === 1 || action.spansEachPass) {
|
||||
|
||||
@@ -26,7 +26,7 @@ type PairSweep = {
|
||||
// How another pair stands when the judged one falls: `moves` where a carry or a merge may move its delimiters, `unsettled` where it may stand or have fallen.
|
||||
type Standing = 'fallen' | 'moves' | 'stands' | 'unsettled'
|
||||
|
||||
// `merges` where a drop may merge runs at the pair's ends, so its delimiters may move; `falls` where it goes back with the first misread pair, itself included unless it merges; `kept` otherwise.
|
||||
// `merges` where a drop may merge runs at the pair's ends, so its delimiters may move; `falls` where it goes back with the first misread pair, as the first pair does unless it merges; `kept` otherwise.
|
||||
type Verdict = 'falls' | 'kept' | 'merges'
|
||||
|
||||
// The runs this pass takes back: the first emphasis run the line misreads and every run that falls with it, else every misflanked highlight run.
|
||||
@@ -109,7 +109,6 @@ function endsAlone(edge: AdfNode | undefined, beside: AdfNode | undefined, mark:
|
||||
return marks.slice(marks.findIndex((held) => identicalMark(held, mark)) + 1).every((held) => !besideTypes.has(held.type))
|
||||
}
|
||||
|
||||
// A pair falls with the first where it falls cleanly, and cannot read whichever character it is written with.
|
||||
function fallsWithFirst(sweep: PairSweep, judged: number): boolean {
|
||||
if (!fallsCleanly(sweep, judged)) return false
|
||||
const spellings = pairSpellings(sweep, judged, judged)
|
||||
|
||||
Reference in New Issue
Block a user