mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-13 12:18:28 +01:00
Answer product-owner round 1: 0 🔴, 0 🟡; scope only backtick runs to outside a directive, and name the kept closer codeSpanCloser
This commit is contained in:
+3
-3
@@ -16,9 +16,9 @@
|
||||
table cell: `[alt](href) ([image](url))`, where it wrote `[alt](url)` and dropped the link's target.
|
||||
- `losslessMarkdownToAdf` names the CommonMark spelling to write when it refuses a directive whose
|
||||
node CommonMark spells, such as `[](href)` for a linked `!adf:mediaSingle`.
|
||||
- Every reader and writer takes time linear in a text holding many unclosed backtick runs, or many
|
||||
`<!--`, `<?`, `<![CDATA[` or `<!` openers without a terminator, outside a directive's `[content]`,
|
||||
where such a text took time quadratic in its length: 160k characters of `<?` took seven seconds
|
||||
- Every reader and writer takes time linear in a text holding many `<!--`, `<?`, `<![CDATA[` or `<!`
|
||||
openers without a terminator, or many unclosed backtick runs outside a directive's `[content]`,
|
||||
where such a text took time quadratic in its length: 160000 characters of `<?` took seven seconds
|
||||
each way, now 50 ms.
|
||||
- The README compares the package with seven other ADF converters, each checked against its
|
||||
published version.
|
||||
|
||||
@@ -20,14 +20,14 @@ export type InlineToken =
|
||||
|
||||
// A text and what its openers look ahead for, read once, so a walk reading a token at every index stays linear in it.
|
||||
export type InlineSource = {
|
||||
readonly closingBacktickRun: (from: number, opener: number) => number | undefined
|
||||
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.
|
||||
readonly terminators: Map<string, number>
|
||||
readonly text: string
|
||||
}
|
||||
|
||||
export function inlineSource(text: string): InlineSource {
|
||||
return { closingBacktickRun: backtickCloser(text), terminators: new Map(), text }
|
||||
return { codeSpanCloser: backtickCloser(text), terminators: new Map(), text }
|
||||
}
|
||||
|
||||
export function readInlineToken(inline: InlineSource, index: number, claims: Claims): InlineToken {
|
||||
@@ -86,7 +86,7 @@ function angleToken(inline: InlineSource, index: number): InlineToken {
|
||||
|
||||
function backtickToken(inline: InlineSource, index: number): InlineToken {
|
||||
const opener = backtickRun(inline.text, index)
|
||||
const closer = inline.closingBacktickRun(index + opener, opener)
|
||||
const closer = inline.codeSpanCloser(index + opener, opener)
|
||||
return closer === undefined ? text(opener) : { kind: 'code-span', opener, width: closer + opener - index }
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user