@stesura/markdown
Converts between markdown and ProseMirror blocks of the Stesura schema. Neither direction throws:
whatever can’t be converted is simplified or dropped and reported as a Warning. The
AI package uses it to exchange documents with the model.
Parse
parseMarkdown
Parse markdown into section_content children, plus note bodies. Never
throws: unsupported constructs are reported, and a failure (e.g. stack
exhaustion on deeply nested input) yields no blocks with a warning.
| Name | Type | Default |
|---|---|---|
markdown | string | |
options | ParseOptions |
ParseOptions
What parseMarkdown takes: the target schema plus document context for validation.
ParseResult
Result of parseMarkdown.
Serialize
serializeBlocks
Serialize section_content children to markdown. Never throws: unsupported
content is reported, and a failure yields empty markdown with a warning.
| Name | Type | Default |
|---|---|---|
blocks | readonly Node[] | |
options | SerializeOptions |
SerializeOptions
What serializeBlocks takes.
SerializeResult
Result of serializeBlocks.
| Name | Type | Default |
|---|---|---|
markdown | string | |
warnings | Warning[] |
Warnings
Warning
A non-fatal degradation. Neither direction throws: lossy input degrades and is reported here. Messages are written to be shown verbatim to the model.
| Name | Type | Default |
|---|---|---|
code | WarningCode | |
message | string |
WarningCode
export type WarningCode =
| "unsupported-node"
| "unsupported-mark"
| "dropped-content"
| "clamped-heading-level"
| "invalid-block-attr"
| "invalid-inline-token"
| "unknown-style"
| "unknown-list-ref"
| "inferred-list-ref"
| "table-simplified"
| "ignored-footnote-definition";The kind of loss a Warning reports.
Extensions
Packages bring markdown support for their own nodes as a MarkdownExtension (for example
mermaidMarkdown from @stesura/mermaid). Register it once per schema, and every
conversion on that schema uses it, including the AI tools’:
import { registerMarkdownExtensions } from '@stesura/markdown'
import { mermaidMarkdown } from '@stesura/mermaid'
registerMarkdownExtensions(schema, mermaidMarkdown)registerMarkdownExtensions
Makes every parseMarkdown/serializeBlocks call on schema use these
extensions (e.g. mermaidMarkdown), callers that know nothing about them
included: the AI tools, attachments, text actions. Later registrations win
on a shared key; options passed to a call win over all of them.
| Name | Type | Default |
|---|---|---|
schema | Schema<any, any> | |
extensions | MarkdownExtension[] |
MarkdownExtension
A package’s markdown support for its own nodes, spread into both
parseMarkdown and serializeBlocks options.
| Name | Type | Default |
|---|---|---|
fenceHandlers | Readonly<Record<string, FenceHandler>> | |
nodeHandlers | Readonly<Record<string, PmNodeHandler>> |
FenceHandler
Builds a node from a fenced code block of one info-string language (e.g.
mermaid). null falls back to a plain code_block.
| Name | Type | Default |
|---|---|---|
value | string | |
attrs | BlockAttrs | |
schema | Schema<any, any> |
MarkdownNodeHandler
A PM → mdast node handler, as SerializeOptions.nodeHandlers takes it.
| Name | Type | Default |
|---|---|---|
node | Node | |
parent | Node | |
state | State<string, string> |