5b1: guarantee the parse direction's position in the type, and name it one level deeper
CI / gate (push) Successful in 9s
CI / gate (push) Successful in 9s
This commit is contained in:
@@ -24,9 +24,9 @@ Pure functions, no I/O, no configuration. ADF is the hub: markdown↔HTML compos
|
||||
|
||||
```ts
|
||||
adfToMarkdown(doc: AdfDocument): Result<string>
|
||||
markdownToAdf(markdown: string): Result<AdfDocument>
|
||||
markdownToAdf(markdown: string): Result<AdfDocument, ParseError>
|
||||
adfToHtml(doc: AdfDocument): Result<string>
|
||||
htmlToAdf(html: string): Result<AdfDocument>
|
||||
htmlToAdf(html: string): Result<AdfDocument, ParseError>
|
||||
markdownToHtml(markdown: string): Result<string> // via ADF
|
||||
htmlToMarkdown(html: string): Result<string> // via ADF
|
||||
isAdfDocument(v: unknown): v is AdfDocument
|
||||
@@ -35,8 +35,12 @@ isAdfDocument(v: unknown): v is AdfDocument
|
||||
`Result<T>` is `{ ok: true; value: T } | { ok: false; error: ConvertError }` — nothing throws.
|
||||
`ConvertError` is `{ code, message, path, position? }`: a code from a closed set, the path of the
|
||||
node it names from the document root, and — parsing — a `{ line, offset }` into the string passed
|
||||
in, at the start of the line the refused block begins on, `line` counted from 1. Emitting reads no
|
||||
source, so an emit error carries no `position`.
|
||||
in, at the start of the line the refused block begins on, `line` counted from 1.
|
||||
|
||||
Parsing a source always names where in it the refusal sits, so `markdownToAdf` and `htmlToAdf`
|
||||
return the narrowed `ParseError`, whose `position` is there to read without a guard. Every other
|
||||
direction emits, from a document with no source behind it, and carries `path` alone — including
|
||||
`markdownToHtml` and `htmlToMarkdown`, where half the refusals come from the emit half.
|
||||
|
||||
## The guarantees
|
||||
|
||||
|
||||
Reference in New Issue
Block a user