mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-15 13:00:26 +01:00
Answer stability round 1: 0 🔴, 6 🟡; share the label limit with readLabel, pin it at 1000 characters, move item 129 to the changelog
This commit is contained in:
@@ -15,7 +15,7 @@ import { identicalMarks, mergeAdjacentText, nodeAttrs, nodeMarks } from '../../a
|
||||
import { inlineNodeModel, takesMark } from '../../adf/inline-nodes.ts'
|
||||
import { joinsWhenRead, textBreakName, textBreakSpelling } from '../adjacent-text.ts'
|
||||
import { matchEmphasis } from '../commonmark/emphasis-matching.ts'
|
||||
import { normalizeLabel, readInlineTarget, readLabel } from '../commonmark/link-syntax.ts'
|
||||
import { labelLimit, normalizeLabel, readInlineTarget, readLabel } from '../commonmark/link-syntax.ts'
|
||||
import { noSpans, readInlineDirective } from '../directive/syntax.ts'
|
||||
import { openingLinkTakesDirective } from '../emit/spelling-questions.ts'
|
||||
import { readCarriedInline } from '../opaque-carry.ts'
|
||||
@@ -431,9 +431,8 @@ function resolveTarget(scan: Scan, start: number, index: number): { definition:
|
||||
if (inline !== undefined) return { definition: inline.definition, length: inline.length }
|
||||
}
|
||||
const label = scan.source.charAt(after) === '[' ? readLabel(scan.source, after) : undefined
|
||||
// CommonMark: a label holds at most 999 characters, so longer link text names no definition.
|
||||
const labelIsText = label === undefined || label.value === ''
|
||||
if (labelIsText && index - start > 999) return undefined
|
||||
if (labelIsText && index - start > labelLimit) return undefined
|
||||
const name = labelIsText ? scan.source.slice(start, index) : label.value
|
||||
const definition = scan.definitions.get(normalizeLabel(name))
|
||||
if (definition === undefined) return undefined
|
||||
@@ -566,7 +565,7 @@ function markPairings(pieces: readonly Piece[], nodes: Inline[][], pairings: rea
|
||||
}
|
||||
for (const pairing of opening.get(index) ?? []) {
|
||||
const type = markType(pairing.opener.character, pairing.used)
|
||||
// A type takes its place from the innermost pairing of it.
|
||||
// Each type once, so a piece's marks stay at most three however deep the pairings nest.
|
||||
const outer = open.at(-1)?.marks.filter((mark) => mark.type !== type) ?? []
|
||||
open.push({ closer: pairing.closer.index, marks: [...outer, { type }] })
|
||||
}
|
||||
|
||||
@@ -1078,8 +1078,12 @@ test('reads the reference links a definition resolves, and leaves the rest liter
|
||||
|
||||
test('reads link text past 999 characters as no label, in every reader', () => {
|
||||
const longest = `foo${' '.repeat(993)}bar`
|
||||
const tooLong = `foo${' '.repeat(1000)}bar`
|
||||
const tooLong = `foo${' '.repeat(994)}bar`
|
||||
const escaped = '\\*'.repeat(499)
|
||||
const escapedTooLong = '\\*'.repeat(500)
|
||||
for (const read of [commonMarkToAdf, losslessMarkdownToAdf, portableMarkdownToAdf]) {
|
||||
assert.deepEqual(content(read(`[a][${escaped}]\n\n[${escaped}]: /u\n`)), [{ content: [marked('a', link('/u'))], type: 'paragraph' }])
|
||||
assert.deepEqual(content(read(`[a][${escapedTooLong}]\n\n[${escapedTooLong}]: /u\n`)), [paragraph(`[a][${'*'.repeat(500)}]`), paragraph(`[${'*'.repeat(500)}]: /u`)])
|
||||
assert.deepEqual(content(read(`[${longest}]\n\n[foo bar]: /u\n`)), [{ content: [marked(longest, link('/u'))], type: 'paragraph' }])
|
||||
assert.deepEqual(content(read(`[${longest}][]\n\n[foo bar]: /u\n`)), [{ content: [marked(longest, link('/u'))], type: 'paragraph' }])
|
||||
assert.deepEqual(content(read(`[${tooLong}]\n\n[foo bar]: /u\n`)), [paragraph(`[${tooLong}]`)])
|
||||
|
||||
Reference in New Issue
Block a user