3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-21 07:32:58 +01:00

Read the emphasis, the links and the lone image CommonMark spells (#34)

This commit is contained in:
2026-08-31 22:33:54 +02:00
parent 5975d8d912
commit cc794d541e
31 changed files with 899 additions and 218 deletions
+8 -1
View File
@@ -2,7 +2,7 @@ import { isUnicodeWhitespace } from './commonmark-grammar.ts'
type DelimiterRun = { canClose: boolean; canOpen: boolean; character: string; length: number }
type EmphasisPairing<Run> = { closer: Run; closerOffset: number; opener: Run; openerOffset: number; used: number }
export type EmphasisPairing<Run> = { closer: Run; closerOffset: number; opener: Run; openerOffset: number; used: number }
type Candidate<Run> = {
head: number
@@ -64,6 +64,13 @@ export function matchEmphasis<Run extends DelimiterRun>(runs: readonly Run[]): E
return pairings
}
export function runLength(text: string, index: number): number {
const character = text.charAt(index)
let length = 0
while (text.charAt(index + length) === character) length += 1
return length
}
function candidates<Run extends DelimiterRun>(runs: readonly Run[]): Candidate<Run> | undefined {
let first: Candidate<Run> | undefined
let previous: Candidate<Run> | undefined