mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-20 15:15:44 +01:00
Answer prose round 2: 0 🔴, 2 🟡 (0 misread); the memo comments say what they hold, the PR body names destinationEnds
This commit is contained in:
@@ -10,7 +10,7 @@ export type LinkPart = { length: number; value: string }
|
|||||||
// Every destination ending at one index shares what follows it: the title and the closing `)`.
|
// Every destination ending at one index shares what follows it: the title and the closing `)`.
|
||||||
type Tail = { end: number; title: string | undefined }
|
type Tail = { end: number; title: string | undefined }
|
||||||
|
|
||||||
// What the targets read in `text` share; `destinationEnds` is walked at the first one.
|
// One memo serves every target in `text`, those in a directive's content included.
|
||||||
export type TargetMemo = { destinationEnds: Int32Array | undefined; tails: Map<number, Tail | undefined>; text: string }
|
export type TargetMemo = { destinationEnds: Int32Array | undefined; tails: Map<number, Tail | undefined>; text: string }
|
||||||
|
|
||||||
// The lossless flavour escapes a quote alone, writing a title holding a backslash or an entity reference as a directive (spec/flavour.md, Marks); the portable flavour writes no directive, so it escapes those too, and a table cell's `|` (README, Portable markdown).
|
// The lossless flavour escapes a quote alone, writing a title holding a backslash or an entity reference as a directive (spec/flavour.md, Marks); the portable flavour writes no directive, so it escapes those too, and a table cell's `|` (README, Portable markdown).
|
||||||
@@ -72,7 +72,7 @@ export function targetMemo(text: string): TargetMemo {
|
|||||||
return { destinationEnds: undefined, tails: new Map(), text }
|
return { destinationEnds: undefined, tails: new Map(), text }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Where an unbracketed destination starting at each index stops, in one pass, for every start a target can have: the index just after a `(`, a space or a control character. Index 0 is a start too, for `readDestination`, which reads from its text's first character.
|
// `ends[start]` is where an unbracketed destination from `start` stops, filled in one pass for every start a target can have: just after a `(`, a space or a control character, and 0, where `readDestination`'s run begins.
|
||||||
function destinationEnds(text: string): Int32Array {
|
function destinationEnds(text: string): Int32Array {
|
||||||
const ends = new Int32Array(text.length + 1)
|
const ends = new Int32Array(text.length + 1)
|
||||||
const open = [0]
|
const open = [0]
|
||||||
|
|||||||
@@ -433,7 +433,7 @@ function resolveTarget(scan: Scan, start: number, index: number): InlineTarget |
|
|||||||
const after = index + 1
|
const after = index + 1
|
||||||
if (scan.source.charAt(after) === '(') {
|
if (scan.source.charAt(after) === '(') {
|
||||||
const inline = readInlineTarget(scan.targets, scan.offset + after)
|
const inline = readInlineTarget(scan.targets, scan.offset + after)
|
||||||
// A target read in the outermost content holds in a directive's content exactly when it ends inside it.
|
// The memo reads the outermost content; a target it reads holds here exactly when the target ends inside `source`.
|
||||||
if (inline !== undefined && after + inline.length <= scan.source.length) return inline
|
if (inline !== undefined && after + inline.length <= scan.source.length) return inline
|
||||||
}
|
}
|
||||||
const label = scan.source.charAt(after) === '[' ? readLabel(scan.source, after) : undefined
|
const label = scan.source.charAt(after) === '[' ? readLabel(scan.source, after) : undefined
|
||||||
|
|||||||
Reference in New Issue
Block a user