Emitter 2c: the inline node directives, the directive marks and the carried whitespace
CI / gate (push) Successful in 5s
CI / gate (push) Successful in 5s
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import type { AdfNode } from './adf-document.ts'
|
||||
import type { JsonValue } from './json-value.ts'
|
||||
import { emitInlineLine } from './markdown-inline.ts'
|
||||
import { emitPipeCell } from './markdown-inline.ts'
|
||||
import { success, type ConvertErrorPath, type Result } from './result.ts'
|
||||
|
||||
export function emitPipeTable(node: AdfNode, path: ConvertErrorPath): Result<string> | undefined {
|
||||
@@ -11,7 +10,8 @@ export function emitPipeTable(node: AdfNode, path: ConvertErrorPath): Result<str
|
||||
const cells: string[] = []
|
||||
for (const [cellIndex, paragraph] of row.entries()) {
|
||||
const content = paragraph.content ?? []
|
||||
const line = content.length === 0 ? success('') : emitInlineLine(content, 'table-cell', [...path, 'content', rowIndex, 'content', cellIndex, 'content', 0])
|
||||
const line = content.length === 0 ? success('') : emitPipeCell(content, [...path, 'content', rowIndex, 'content', cellIndex, 'content', 0])
|
||||
if (line === undefined) return undefined
|
||||
if (!line.ok) return line
|
||||
cells.push(line.value)
|
||||
}
|
||||
@@ -49,18 +49,5 @@ function plainParagraph(cell: AdfNode): AdfNode | undefined {
|
||||
const content = cell.content ?? []
|
||||
const paragraph = content[0]
|
||||
if (paragraph === undefined || content.length !== 1 || paragraph.type !== 'paragraph' || !isPlain(paragraph)) return undefined
|
||||
return (paragraph.content ?? []).some(spellsPipeAsSyntax) ? undefined : paragraph
|
||||
}
|
||||
|
||||
// A pipe the inline layer emits as syntax takes no backslash, so the cell has no pipe spelling.
|
||||
function spellsPipeAsSyntax(child: AdfNode): boolean {
|
||||
return (child.marks ?? []).some((mark) => {
|
||||
if (mark.type === 'code') return (child.text ?? '').includes('|')
|
||||
if (mark.type !== 'link') return false
|
||||
return holdsPipe(mark.attrs?.['href']) || holdsPipe(mark.attrs?.['title'])
|
||||
})
|
||||
}
|
||||
|
||||
function holdsPipe(value: JsonValue | undefined): boolean {
|
||||
return typeof value === 'string' && value.includes('|')
|
||||
return paragraph
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user