Answer the stability nits: the spellings a position hint names, and the fault its name owns
CI / gate (push) Successful in 9s
CI / gate (push) Successful in 9s
This commit is contained in:
+3
-3
@@ -263,9 +263,9 @@ The moon, at night.
|
|||||||
a `mediaSingle` with attrs exactly `{"layout":"center"}` holding an `external` `media` — `url`
|
a `mediaSingle` with attrs exactly `{"layout":"center"}` holding an `external` `media` — `url`
|
||||||
from the destination, `alt` the description's plain-text content when non-empty — a link or image
|
from the destination, `alt` the description's plain-text content when non-empty — a link or image
|
||||||
inside it contributing its own text, a node spelling its text in the content slot contributing
|
inside it contributing its own text, a node spelling its text in the content slot contributing
|
||||||
that text, and a break of either kind a space. `adfToMarkdown`
|
that text, and a break of either kind a space. `adfToMarkdown` emits the image form for exactly
|
||||||
emits the image form for exactly that shape — those attrs and no others, no marks on either
|
that shape — those attrs and no others, no marks on either node, no caption, and a `media`
|
||||||
node, no caption, and a `media` carrying nothing beyond `alt`, `type` and `url` — and only where
|
carrying nothing beyond `alt`, `type` and `url` — and only where
|
||||||
CommonMark spells the pair: a destination or a description the image form cannot hold, an empty
|
CommonMark spells the pair: a destination or a description the image form cannot hold, an empty
|
||||||
`alt` included, takes the directive form instead. An image amid
|
`alt` included, takes the directive form instead. An image amid
|
||||||
other text, or one carrying a title, is a named error: `mediaInline` carries a media
|
other text, or one carrying a title, is a named error: `mediaInline` carries a media
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export function readDirectiveMark(name: string, attributes: DirectiveAttributes,
|
|||||||
return success(Object.keys(attrs.value).length === 0 ? { type: name } : { attrs: attrs.value, type: name })
|
return success(Object.keys(attrs.value).length === 0 ? { type: name } : { attrs: attrs.value, type: name })
|
||||||
}
|
}
|
||||||
|
|
||||||
export function markSpellingFault(name: string): ConvertFault | undefined {
|
export function inlineMarkSpellingFault(name: string): ConvertFault | undefined {
|
||||||
const spelling = markSpelling(name)
|
const spelling = markSpelling(name)
|
||||||
if (spelling === undefined) return undefined
|
if (spelling === undefined) return undefined
|
||||||
return { code: 'unsupported-node-shape', message: `${name} is spelled ${markdownForm(spelling) ?? `:${name}[…]`}, never as a block directive` }
|
return { code: 'unsupported-node-shape', message: `${name} is spelled ${markdownForm(spelling) ?? `:${name}[…]`}, never as a block directive` }
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { blockDirective } from '../../adf/block-directives.ts'
|
|||||||
import { carryName } from '../opaque-carry.ts'
|
import { carryName } from '../opaque-carry.ts'
|
||||||
import { failure, faulted, success, type ConvertErrorPath, type Result } from '../../result.ts'
|
import { failure, faulted, success, type ConvertErrorPath, type Result } from '../../result.ts'
|
||||||
import { inlineDirective } from '../../adf/inline-directives.ts'
|
import { inlineDirective } from '../../adf/inline-directives.ts'
|
||||||
import { markSpellingFault } from './directive-marks.ts'
|
import { inlineMarkSpellingFault } from './directive-marks.ts'
|
||||||
import { marksAttribute, readMarkValues } from '../block-directive-marks.ts'
|
import { marksAttribute, readMarkValues } from '../block-directive-marks.ts'
|
||||||
import { readVocabulary } from './directive-attributes.ts'
|
import { readVocabulary } from './directive-attributes.ts'
|
||||||
import { slotLineEndingFault } from '../directive-syntax.ts'
|
import { slotLineEndingFault } from '../directive-syntax.ts'
|
||||||
@@ -69,15 +69,17 @@ export function readInlineDirectiveNode(
|
|||||||
|
|
||||||
// A name the other position spells names that spelling, never the code a later MINOR may fill (AGENTS.md §8).
|
// A name the other position spells names that spelling, never the code a later MINOR may fill (AGENTS.md §8).
|
||||||
function inlineSpellingFault(name: string): ConvertFault | undefined {
|
function inlineSpellingFault(name: string): ConvertFault | undefined {
|
||||||
const mark = markSpellingFault(name)
|
const mark = inlineMarkSpellingFault(name)
|
||||||
if (mark !== undefined) return mark
|
if (mark !== undefined) return mark
|
||||||
if (inlineDirective(name) === undefined && name !== textDirectiveName) return undefined
|
if (inlineDirective(name) === undefined && name !== textDirectiveName) return undefined
|
||||||
return { code: 'unsupported-node-shape', message: `${name} takes the inline form, :${name}` }
|
return { code: 'unsupported-node-shape', message: `${name} takes the inline form, :${name}{…}` }
|
||||||
}
|
}
|
||||||
|
|
||||||
function blockSpellingFault(name: string): ConvertFault | undefined {
|
function blockSpellingFault(name: string): ConvertFault | undefined {
|
||||||
if (blockDirective(name) === undefined) return undefined
|
const directive = blockDirective(name)
|
||||||
return { code: 'unsupported-node-shape', message: `${name} takes the block form, ::${name}` }
|
if (directive === undefined) return undefined
|
||||||
|
const form = directive.contentModel === 'none' ? `::${name}` : `:::${name}`
|
||||||
|
return { code: 'unsupported-node-shape', message: `${name} takes the block form, ${form}` }
|
||||||
}
|
}
|
||||||
|
|
||||||
// spec/flavour.md, Inline nodes: the slot is plain text, its adjacent nodes already merged.
|
// spec/flavour.md, Inline nodes: the slot is plain text, its adjacent nodes already merged.
|
||||||
|
|||||||
@@ -254,9 +254,10 @@ test('names the directive name no node reads back to', () => {
|
|||||||
test('names the position a directive name the other one spells belongs to', () => {
|
test('names the position a directive name the other one spells belongs to', () => {
|
||||||
assert.equal(content(markdownToAdf(':::em\na\n:::\n')), 'unsupported-node-shape: em is spelled _x_, never as a block directive')
|
assert.equal(content(markdownToAdf(':::em\na\n:::\n')), 'unsupported-node-shape: em is spelled _x_, never as a block directive')
|
||||||
assert.equal(content(markdownToAdf('::underline\n')), 'unsupported-node-shape: underline is spelled :underline[…], never as a block directive')
|
assert.equal(content(markdownToAdf('::underline\n')), 'unsupported-node-shape: underline is spelled :underline[…], never as a block directive')
|
||||||
assert.equal(content(markdownToAdf('::text {text=" "}\n')), 'unsupported-node-shape: text takes the inline form, :text')
|
assert.equal(content(markdownToAdf('::text {text=" "}\n')), 'unsupported-node-shape: text takes the inline form, :text{…}')
|
||||||
assert.equal(content(markdownToAdf('::date {timestamp=1}\n')), 'unsupported-node-shape: date takes the inline form, :date')
|
assert.equal(content(markdownToAdf('::date {timestamp=1}\n')), 'unsupported-node-shape: date takes the inline form, :date{…}')
|
||||||
assert.equal(content(markdownToAdf(':paragraph[a]\n')), 'unsupported-node-shape: paragraph takes the block form, ::paragraph')
|
assert.equal(content(markdownToAdf(':paragraph[a]\n')), 'unsupported-node-shape: paragraph takes the block form, :::paragraph')
|
||||||
|
assert.equal(content(markdownToAdf(':rule[a]\n')), 'unsupported-node-shape: rule takes the block form, ::rule')
|
||||||
assert.equal(code(markdownToAdf(':::widget\na\n:::\n')), 'unknown-directive-name')
|
assert.equal(code(markdownToAdf(':::widget\na\n:::\n')), 'unknown-directive-name')
|
||||||
assert.equal(code(markdownToAdf(':widget[a]\n')), 'unknown-directive-name')
|
assert.equal(code(markdownToAdf(':widget[a]\n')), 'unknown-directive-name')
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -2,17 +2,16 @@ import type { ConvertFault } from '../result.ts'
|
|||||||
import type { DirectiveSpan, Read } from './directive-syntax.ts'
|
import type { DirectiveSpan, Read } from './directive-syntax.ts'
|
||||||
import { spellAttributes, spellLeafDirective, spellStringAttribute } from './directive-syntax.ts'
|
import { spellAttributes, spellLeafDirective, spellStringAttribute } from './directive-syntax.ts'
|
||||||
|
|
||||||
export const textDirectiveName = 'text'
|
const name = 'text'
|
||||||
|
|
||||||
const whitespaceRun = /^(?:[ \t]+|\n+)$/
|
const whitespaceRun = /^(?:[ \t]+|\n+)$/
|
||||||
|
|
||||||
|
export const textDirectiveName = name
|
||||||
|
|
||||||
export function spellTextDirective(text: string): string {
|
export function spellTextDirective(text: string): string {
|
||||||
const name = textDirectiveName
|
|
||||||
return spellLeafDirective(name, spellAttributes([[name, spellStringAttribute(text)]]))
|
return spellLeafDirective(name, spellAttributes([[name, spellStringAttribute(text)]]))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function readTextDirective(span: DirectiveSpan): Read<string> | undefined {
|
export function readTextDirective(span: DirectiveSpan): Read<string> | undefined {
|
||||||
const name = textDirectiveName
|
|
||||||
if (span.name !== name) return undefined
|
if (span.name !== name) return undefined
|
||||||
if (span.content !== undefined) return { fault: unsupported(`${name} takes no content`) }
|
if (span.content !== undefined) return { fault: unsupported(`${name} takes no content`) }
|
||||||
const spelled = span.attributes.get(name)
|
const spelled = span.attributes.get(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user