0.3.1 • Published 9 months ago

@awesome-myst/myst-zod v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

myst-zod

CI NPM Version JSR

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-zod

or

deno add jsr:@awesome-myst/myst-zod

Usage

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:

  1. rootSchema - the root schema for MyST Markdown AST.
  2. pageFrontmatterSchema - the frontmatter schema for a MyST Markdown article or documentation page.
  3. projectFrontmatterSchema - the frontmatter schema for a MyST book or project documentation.
  4. 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
0.3.1

9 months ago

0.3.0

9 months ago

0.2.2

9 months ago

0.1.6

9 months ago

0.1.5

9 months ago

0.1.0

9 months ago

0.0.1

10 months ago