3
0
mirror of https://github.com/larvit/adf-codec.git synced 2026-11-17 13:50:25 +01:00

Ship htmlToAdf: read back exactly the HTML adfToHtml writes, a carry element from its data-adf alone, any other HTML refused

This commit is contained in:
2026-10-26 21:47:30 +01:00
committed by Lillem4n
parent 905b039866
commit 51e37f68df
26 changed files with 880 additions and 74 deletions
+2 -9
View File
@@ -12,6 +12,7 @@ import { failure, faulted, positioned, success, type ConvertErrorPath, type Pars
import { flavourClaims } from '../flavour.ts'
import { languageSlot } from '../code-language.ts'
import { largestNesting } from '../../nesting.ts'
import { notAString } from '../../not-a-string.ts'
import { parseBlocks } from './blocks.ts'
import { parseInlineContent } from './inline-content.ts'
import { readBlockDirectiveNode } from '../directive/node-reading.ts'
@@ -47,7 +48,7 @@ export function readDocument(markdown: string, readAs: ReadAs): Result<AdfDocume
}
function readMarkdown(markdown: string, readAs: ReadAs): Result<AdfDocument> {
if (typeof markdown !== 'string') return failure('not-a-string', `markdown is a string: found ${typeName(markdown)}`, [])
if (typeof markdown !== 'string') return notAString(markdown, 'markdown')
const parsed = parseBlocks(markdown, readAs.flavour)
const [only] = parsed.blocks
if (parsed.blocks.length === 1 && only?.kind === 'directive' && only.name === documentName) {
@@ -59,14 +60,6 @@ function readMarkdown(markdown: string, readAs: ReadAs): Result<AdfDocument> {
return content.ok ? success({ content: content.value, type: 'doc', version: 1 }) : content
}
// `typeof` alone, since anything more throws on a revoked Proxy.
function typeName(value: unknown): string {
if (value === null) return 'null'
const type = typeof value
if (type === 'undefined') return type
return type === 'object' ? 'an object' : `a ${type}`
}
export function readBlocks(blocks: readonly Block[], reading: Reading, path: ConvertErrorPath, depth: number): Result<AdfNode[]> {
if (depth > largestNesting) return tooDeep(path)
const content: AdfNode[] = []