diff --git a/src/markdown/commonmark/backtick-runs.ts b/src/markdown/commonmark/backtick-runs.ts index 502a51f..d0bef98 100644 --- a/src/markdown/commonmark/backtick-runs.ts +++ b/src/markdown/commonmark/backtick-runs.ts @@ -8,7 +8,7 @@ export function backtickRun(text: string, index: number): number { // 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. export function backtickCloser(text: string): (from: number, opener: number) => number | undefined { - const asked = new Map() + const cursors = new Map() const starts = new Map() for (let start = text.indexOf('`'); start !== -1; ) { const length = runLength(text, start) @@ -20,10 +20,10 @@ export function backtickCloser(text: string): (from: number, opener: number) => return (from, opener) => { const runs = starts.get(opener) if (runs === undefined) return undefined - let at = asked.get(opener) ?? 0 + let at = cursors.get(opener) ?? 0 if ((runs[at - 1] ?? -1) >= from) at = 0 while ((runs[at] ?? Infinity) < from) at += 1 - asked.set(opener, at) + cursors.set(opener, at) return runs[at] } } diff --git a/src/markdown/inline-tokens.test.ts b/src/markdown/inline-tokens.test.ts index 19879ca..b597b9f 100644 --- a/src/markdown/inline-tokens.test.ts +++ b/src/markdown/inline-tokens.test.ts @@ -9,8 +9,13 @@ import { losslessMarkdownToAdf } from './parse/markdown-to-adf.ts' const constructs = ['', '', ''] -test('an HTML construct whose terminator starts right after its opener reads as HTML', () => { - for (const construct of constructs) assert.equal(readInlineToken(inlineSource(`a ${construct}`), 2, flavourClaims.commonmark).kind, 'html', construct) +// CommonMark 0.31.2, Raw HTML: the terminator must start after the opener, and may start right after it. +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']] + for (const [text, kind] of cases) { + const at = text.lastIndexOf('<') + assert.equal(readInlineToken(inlineSource(`a ${text}`), at + 2, flavourClaims.commonmark).kind, kind, text) + } }) test('text spelling such a construct round-trips', () => {