mirror of
https://github.com/larvit/adf-codec.git
synced 2026-11-18 14:15:44 +01:00
Answer prose round 1: 0 🔴, 7 🟡; state the seam's comments and the decision exactly, and reflow
This commit is contained in:
@@ -22,7 +22,7 @@ type BlockContainer = 'directive' | 'document' | 'list-item'
|
||||
type Delimiters = readonly [string, string]
|
||||
// headroom: the nesting levels the deepest node below may still spend before `largestNesting` refuses it.
|
||||
export type EmittedBlock = SpelledBlock & { headroom: number }
|
||||
// A flavour's own blocks, spelled before CommonMark's, and the openings its reader claims, which a list item or quote escapes.
|
||||
// spell: the flavour's own blocks, tried before CommonMark's; claimsItem, claimsQuote: whether a list item's or quote's text opens with a marker the flavour's reader would take, so the writer escapes it.
|
||||
export type FlavourBlockWriters = {
|
||||
claimsItem: (text: string) => boolean
|
||||
claimsQuote: (text: string) => boolean
|
||||
@@ -202,7 +202,7 @@ function alertEscaped(body: string, writing: Writing): string {
|
||||
return writing.flavour === 'portable' && writing.blocks.claimsQuote(body) ? `\\${body}` : body
|
||||
}
|
||||
|
||||
// Each quote speller calls it directly, not through a wrapper, so a quote level spends one frame between walks (docs/decisions.md §Nothing recurses unbounded).
|
||||
// Quote spellers call this directly, never through a wrapper: each frame a quote level adds lowers the depth the stack holds (docs/decisions.md §Nothing recurses unbounded).
|
||||
export function quotedBlocks(node: AdfNode, path: ConvertErrorPath, depth: number, writing: Writing, bodyText: (body: string) => string): Result<EmittedBlock> {
|
||||
const inner = walkBlocks(nodeContent(node), path, depth + 1, writing)
|
||||
if (!inner.ok) return inner
|
||||
|
||||
@@ -2,7 +2,7 @@ export type Flavour = 'commonmark' | 'lossless' | 'portable'
|
||||
|
||||
export type WrittenFlavour = Exclude<Flavour, 'commonmark'>
|
||||
|
||||
// What a reader reads past CommonMark, and so what its writer escapes, but for the portable callouts and task lists that `FlavourBlockReaders` and `FlavourBlockWriters` carry (docs/decisions.md §Each call names its flavour).
|
||||
// What a reader reads past CommonMark, and so what its writer escapes; the portable flavour's alerts, callouts and task markers are left to `FlavourBlockReaders` and `FlavourBlockWriters` (docs/decisions.md §Each call names its flavour).
|
||||
export type Claims = {
|
||||
carryFence: boolean
|
||||
directives: boolean
|
||||
@@ -17,7 +17,7 @@ type WrittenClaims = Claims & { pipeTables: 'flavour' | 'gfm'; strikethrough: tr
|
||||
// Directives exclude highlights: a directive's slot reads `==`.
|
||||
type ReadClaims = Claims & ({ directives: false } | { directives: true; highlights: false })
|
||||
|
||||
// A folded callout inside an expand directive would read as an expand, not a nestedExpand, so the portable flavour reads no directives.
|
||||
// Pinned false: inside an expand directive, a folded callout would read as an expand, not a nestedExpand.
|
||||
export const flavourClaims: Readonly<{ commonmark: ReadClaims; portable: { directives: false } } & Record<WrittenFlavour, ReadClaims & WrittenClaims>> = {
|
||||
commonmark: { carryFence: false, directives: false, highlights: false, pipeTables: false, strikethrough: false },
|
||||
lossless: { carryFence: true, directives: true, highlights: false, pipeTables: 'flavour', strikethrough: true },
|
||||
|
||||
@@ -19,7 +19,7 @@ import { spellStringAttribute, unsupportedNodeShape } from '../directive/syntax.
|
||||
import { spellsEmpty } from '../directive/empty-keys.ts'
|
||||
import { withinEngineLimits } from '../length-bound.ts'
|
||||
|
||||
// A flavour's own reading of a quote and of a bullet list, which may read to several blocks; `path` is the container's, `index` the list's among its blocks.
|
||||
// A flavour's own reading of a quote, and of a bullet list into one or more blocks; `path` is the container's, `index` the list's place among the container's blocks.
|
||||
export type FlavourBlockReaders = {
|
||||
bulletList: (items: readonly Block[][], reading: FlavourReading, path: ConvertErrorPath, depth: number, index: number) => Result<AdfNode[]>
|
||||
quote: (blocks: readonly Block[], reading: FlavourReading, path: ConvertErrorPath, depth: number) => Result<AdfNode>
|
||||
|
||||
@@ -16,7 +16,6 @@ type Paragraph = Extract<Block, { kind: 'paragraph' }>
|
||||
// The paragraph a task marker opens: a task item holds no image, so a lone one there reads as its linked alt text.
|
||||
type TaskParagraph = { kind: 'taskParagraph'; position: SourcePosition; text: string }
|
||||
|
||||
// Inside an expand, a folded callout reads as a nestedExpand.
|
||||
const expandBlockReaders: FlavourBlockReaders = { bulletList: bulletBlocks, quote: quoteReader('nestedExpand') }
|
||||
const portableBlockReaders: FlavourBlockReaders = { bulletList: bulletBlocks, quote: quoteReader('expand') }
|
||||
|
||||
@@ -48,7 +47,7 @@ function paragraphsOf(position: SourcePosition, ...texts: string[]): Paragraph[]
|
||||
return texts.filter((text) => text !== '').map((text) => ({ kind: 'paragraph', position, text }))
|
||||
}
|
||||
|
||||
// The closure is the reader rather than a wrapper around one, so a quote level spends one stack frame (docs/decisions.md §Nothing recurses unbounded).
|
||||
// The closure is the reader itself, never a wrapper calling one: a wrapper adds a stack frame to every quote level (docs/decisions.md §Nothing recurses unbounded).
|
||||
function quoteReader(foldedType: 'expand' | 'nestedExpand'): FlavourBlockReaders['quote'] {
|
||||
return (blocks, reading, path, depth) => {
|
||||
const [first, ...body] = blocks
|
||||
|
||||
Reference in New Issue
Block a user