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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user