mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-14 12:30:26 +01:00
Answer prose round 1: 0 🔴, 5 🟡; define the closer in place, and say the kept source is one per text
This commit is contained in:
@@ -4,9 +4,8 @@ export function backtickRun(text: string, index: number): number {
|
||||
return text.charAt(index) === '`' ? runLength(text, index) : 0
|
||||
}
|
||||
|
||||
// As `closingBacktickRun`, for `from` past the end of an opener's run, with each run's start read once by its length.
|
||||
// Readers ask with `from` rising, which keeps each length's cursor moving forward, so asking at every opener stays
|
||||
// linear in the text; an ask behind the cursor restarts that length from its first run.
|
||||
// Where the first run of exactly `opener` backticks at or after `from` begins, `from` never inside a run. Ask with
|
||||
// `from` rising, so each length's cursor only moves forward and a walk stays linear; an earlier `from` rescans that length.
|
||||
export function backtickCloser(text: string): (from: number, opener: number) => number | undefined {
|
||||
const cursors = new Map<number, number>()
|
||||
const starts = new Map<number, number[]>()
|
||||
|
||||
@@ -9,7 +9,7 @@ import { losslessMarkdownToAdf } from './parse/markdown-to-adf.ts'
|
||||
|
||||
const constructs = ['<!A>', '<??>', '<![CDATA[]]>']
|
||||
|
||||
// CommonMark 0.31.2, Raw HTML: the terminator must start after the opener, and may start right after it.
|
||||
// CommonMark 0.31.2, Raw HTML: the terminator may start right after the opener, never inside it; `<!-->` and `<!--->` are whole comments.
|
||||
test('an HTML opener reads as HTML only where its terminator starts after it', () => {
|
||||
const cases: [string, string][] = [...constructs.map((text): [string, string] => [text, 'html']), ['<!---->', 'html'], ['?> <? ?>', 'html'], ['?> <?', 'text'], ['<?>', 'text']]
|
||||
for (const [text, kind] of cases) {
|
||||
|
||||
@@ -18,10 +18,10 @@ export type InlineToken =
|
||||
| { closes: boolean; kind: 'highlight'; opens: boolean; width: number }
|
||||
| { construct: string; kind: 'html' }
|
||||
|
||||
// A text and what its openers look ahead for, read once, so a walk reading a token at every index stays linear in it.
|
||||
// Build one per text and pass it to every `readInlineToken` call on that text, so a walk stays linear in the text's length.
|
||||
export type InlineSource = {
|
||||
readonly codeSpanCloser: (from: number, opener: number) => number | undefined
|
||||
// Each HTML construct terminator's last start in the text, -1 for none, read the first time an opener asks.
|
||||
// Where each HTML terminator last starts in the text, -1 for none; filled the first time an opener asks.
|
||||
readonly terminators: Map<string, number>
|
||||
readonly text: string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user