3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-21 23:46:21 +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:
2026-10-18 10:52:07 +02:00
committed by Lillem4n
parent 26446c0b89
commit 637fbc914c
2 changed files with 6 additions and 6 deletions
+3 -3
View File
@@ -16,9 +16,9 @@
table cell: `[alt](href) ([image](url))`, where it wrote `[alt](url)` and dropped the link's target. 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 - `losslessMarkdownToAdf` names the CommonMark spelling to write when it refuses a directive whose
node CommonMark spells, such as `[![alt](url)](href)` for a linked `!adf:mediaSingle`. node CommonMark spells, such as `[![alt](url)](href)` for a linked `!adf:mediaSingle`.
- Every reader and writer takes time linear in a text holding many unclosed backtick runs, or many - Every reader and writer takes time linear in a text holding many `<!--`, `<?`, `<![CDATA[` or `<!`
`<!--`, `<?`, `<![CDATA[` or `<!` openers without a terminator, outside a directive's `[content]`, openers without a terminator, or many unclosed backtick runs outside a directive's `[content]`,
where such a text took time quadratic in its length: 160k characters of `<?` took seven seconds where such a text took time quadratic in its length: 160000 characters of `<?` took seven seconds
each way, now 50 ms. each way, now 50 ms.
- The README compares the package with seven other ADF converters, each checked against its - The README compares the package with seven other ADF converters, each checked against its
published version. published version.
+3 -3
View File
@@ -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. // 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 = { 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. // 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 terminators: Map<string, number>
readonly text: string readonly text: string
} }
export function inlineSource(text: string): InlineSource { 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 { 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 { function backtickToken(inline: InlineSource, index: number): InlineToken {
const opener = backtickRun(inline.text, index) 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 } return closer === undefined ? text(opener) : { kind: 'code-span', opener, width: closer + opener - index }
} }