0.3.1 • Published 9 months ago
@awesome-myst/myst-zod v0.3.1
myst-zod
Zod schema for MyST Markdown
Parse MyST Markdown abstract syntax trees (ASTs) with a Zod schema. This package provides a set of Zod schemas that can be used to validate and parse MyST Markdown ASTs.
Installation
npm install @awesome-myst/myst-zodor
deno add jsr:@awesome-myst/myst-zodUsage
A Zod schema is a TypeScript type-safe way to validate and parse data. The
rootSchema is a Zod schema that can be used to validate and parse MyST
Markdown ASTs.
import { rootSchema } from "@awesome-myst/myst-zod";
const myst = {
type: "root",
children: [
{
type: "paragraph",
children: [
{
type: "text",
value: "Hello, world!",
},
],
},
],
};
const result = rootSchema.parse(myst);
console.log(result);
// {
// type: 'root',
// children: [ { type: 'paragraph', children: [Array] } ]
// }An
example validator application
is available
in the examples directory.
The example allows for selection from three commonly-used MyST schemas:
rootSchema- the root schema for MyST Markdown AST.pageFrontmatterSchema- the frontmatter schema for a MyST Markdown article or documentation page.projectFrontmatterSchema- the frontmatter schema for a MyST book or project documentation.xrefSchema- the cross-reference schema for a MyST Markdown project.
See also awesome-myst for more information about the MyST Markdown format.
API
See the API docs.
License
MIT License. See LICENSE for details.
Contributing
Contributions are welcome!
To run the tests, use the following command:
deno test -ER