35b - the writer spells the plain flavour and escapes text that would read as its markers
This commit is contained in:
@@ -7,9 +7,9 @@ import type { LinkDefinition } from '../commonmark/link-syntax.ts'
|
||||
import { backslashEscape, decodeTextEscapes, inlineHtmlConstruct, readBracketedAutolink, readEmailAutolink, trimTrailingSpace } from '../commonmark/grammar.ts'
|
||||
import { backtickRun, closingBacktickRun } from '../commonmark/backtick-runs.ts'
|
||||
import { commonMarkLink, linkHref } from '../mark-spellings.ts'
|
||||
import { delimiterFlags, isWordCharacter, matchEmphasis, runLength } from '../commonmark/emphasis-matching.ts'
|
||||
import { highlightDelimiter } from '../plain-conventions.ts'
|
||||
import { delimiterFlags, matchEmphasis, runLength } from '../commonmark/emphasis-matching.ts'
|
||||
import { failure, faulted, success, type ConvertErrorPath, type Result } from '../../result.ts'
|
||||
import { highlightDelimiter, highlightFlanking } from '../plain-conventions.ts'
|
||||
import { inlineNodeModel } from '../../adf/inline-nodes.ts'
|
||||
import { mergeAdjacentText, sameMarks } from '../../adf/editor-normal.ts'
|
||||
import { noSpans, readInlineDirective } from '../directive-syntax.ts'
|
||||
@@ -301,22 +301,14 @@ function readDelimiterRun(scan: Scan, index: number): number {
|
||||
return index + length
|
||||
}
|
||||
|
||||
// A delimiter is bounded outside by the code point beyond it, and flanks by the character inside it.
|
||||
function readEquals(scan: Scan, index: number): number {
|
||||
if (!scan.highlights || !scan.source.startsWith(highlightDelimiter, index)) {
|
||||
scan.pending += '='
|
||||
return index + 1
|
||||
}
|
||||
const end = index + highlightDelimiter.length
|
||||
const before = Array.from(scan.source.slice(Math.max(0, index - 2), index)).at(-1) ?? ''
|
||||
const after = Array.from(scan.source.slice(end, end + 2))[0] ?? ''
|
||||
flush(scan, false)
|
||||
scan.pieces.push({ closes: flanks(before) && !isWordCharacter(after), kind: 'highlight', opens: flanks(after) && !isWordCharacter(before) })
|
||||
return end
|
||||
}
|
||||
|
||||
function flanks(character: string): boolean {
|
||||
return character !== '' && !/\s/.test(character)
|
||||
scan.pieces.push({ ...highlightFlanking(scan.source, index), kind: 'highlight' })
|
||||
return index + highlightDelimiter.length
|
||||
}
|
||||
|
||||
function readAutolink(source: string, index: number): { length: number; node: AdfNode } | undefined {
|
||||
|
||||
@@ -10,11 +10,11 @@ import { commonMarkSpelling, type SpellingMemo } from '../emit/adf-to-markdown.t
|
||||
import { failure, faulted, positioned, success, type ConvertErrorPath, type ParseError, type Result, type SourcePosition } from '../../result.ts'
|
||||
import { languageSlot } from '../code-language.ts'
|
||||
import { largestNesting } from '../../nesting.ts'
|
||||
import { leadingMarker, readAlertMarker, readTaskMarker } from '../plain-conventions.ts'
|
||||
import { listBreakName, listBreakSpelling } from '../block-directive.ts'
|
||||
import { nodeAttrs, nodeContent } from '../../adf/document.ts'
|
||||
import { parseBlocks } from './blocks.ts'
|
||||
import { parseInlineContent } from './inline-content.ts'
|
||||
import { readAlertMarker, readTaskMarker } from '../plain-conventions.ts'
|
||||
import { readBlockDirectiveNode } from './directive-nodes.ts'
|
||||
import { unsupportedNodeShape } from '../directive-syntax.ts'
|
||||
|
||||
@@ -102,10 +102,8 @@ function readBlock(block: Block, reading: Reading, path: ConvertErrorPath, depth
|
||||
|
||||
function markerLed<T extends { length: number }>(block: Block | undefined, read: (text: string) => T | undefined): { marker: T; position: SourcePosition; text: string } | undefined {
|
||||
if (block?.kind !== 'paragraph') return undefined
|
||||
const marker = read(block.text)
|
||||
if (marker === undefined) return undefined
|
||||
const text = block.text.slice(marker.length)
|
||||
return text === '' || /^(?:[ \t\n]|\\\n)/.test(text) ? { marker, position: block.position, text } : undefined
|
||||
const marker = leadingMarker(block.text, read)
|
||||
return marker === undefined ? undefined : { marker, position: block.position, text: block.text.slice(marker.length) }
|
||||
}
|
||||
|
||||
function markerLine(text: string): { line: string; rest: string } {
|
||||
@@ -179,7 +177,7 @@ function directiveNode(block: DirectiveBlock, reading: Reading, path: ConvertErr
|
||||
const inExpand = reading.inExpand || read.value.node.type === 'expand' || read.value.node.type === 'nestedExpand'
|
||||
const built = directiveBody(read.value, block.blocks, { ...reading, inExpand }, path, depth)
|
||||
if (!built.ok) return built
|
||||
const readable = commonMarkSpelling(built.value, path, depth, reading.memo)
|
||||
const readable = commonMarkSpelling(built.value, path, depth, { flavour: 'lossless', memo: reading.memo })
|
||||
if (readable === undefined) return built
|
||||
if (!readable.ok) return readable
|
||||
return failure('unsupported-node-shape', `${built.value.type} takes the CommonMark spelling, not the directive form`, path)
|
||||
|
||||
Reference in New Issue
Block a user