# very-small-parser

> A very small Markdown, HTML, and CSS parser.

Latest version **1.15.0** (published 2026-04-29) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install very-small-parser
pnpm add very-small-parser
yarn add very-small-parser
bun add very-small-parser
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.15.0 |
| Published | 2026-04-29 |
| First published | 2024-11-24 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 220.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 25 |
| Author | streamich |
| Maintainers | streamich |
| Keywords | parser, peg, context, markdown, md, mdast, html, css, tiny, small |

## Links

- npm: https://www.npmjs.com/package/very-small-parser
- Repository: https://github.com/streamich/very-small-parser
- Issues: https://github.com/streamich/very-small-parser/issues
- Funding: https://github.com/sponsors/very-small-parser
- npm.io page: https://npm.io/package/very-small-parser

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 1.15.0 (latest) — 2026-04-29
- 1.14.0 — 2025-07-27
- 1.13.0 — 2025-06-20
- 1.12.0 — 2025-03-08
- 1.11.0 — 2024-12-20
- 1.10.0 — 2024-12-20
- 1.9.0 — 2024-12-20
- 1.8.0 — 2024-12-18
- 1.7.0 — 2024-12-18
- 1.6.0 — 2024-12-16
- 1.5.0 — 2024-12-12
- 1.4.0 — 2024-12-08
- 1.3.0 — 2024-12-07
- 1.2.0 — 2024-11-27
- 1.1.0 — 2024-11-24
- … 1 more at https://npm.io/package/very-small-parser/versions

## README

# `very-small-parser`

- JavaScript parser for Markdown, HTML, and inline CSS.
- [Tiny](https://cdn.jsdelivr.net/npm/very-small-parser/dist/module.js), just over 4KB.
- Runs in browser and Node.js.
- No dependencies.
- Markdown is parsed into [MDAST (Markdown Abstract Syntax Tree)](https://github.com/syntax-tree/mdast).
- HTML is parsed into [HAST (Hypertext Abstract Syntax Tree)](https://github.com/syntax-tree/hast).


## Usage

[__Live demo__](https://jsfiddle.net/yd5eL1cb/)

On the web you can simply import the module using a script tag.

Using ESM.sh:

```html
<script type="module">
  import { markdown } from '//esm.sh/very-small-parser';

  const ast = markdown.block.parsef('Hello __world__!');
  console.log(ast);
</script>
```

Using jsDelivr:

```html
<script type="module">
  import { markdown } from '//esm.run/very-small-parser';

  const ast = markdown.block.parsef('Hello __world__!');
  console.log(ast);
</script>
```

To use TypeScript types or import into a Node.js project, you can install the package from npm:

```sh
npm install very-small-parser
```


## Reference

### Markdown

Parse Markdown document (block elements):

```js
import { markdown } from 'very-small-parser';

const ast = markdown.block.parsef('Hello __world__!');
```

Parse Markdown inline markup only:

```js
const ast = markdown.inline.parse('Hello __world__!');
```

Detect if text is likely to be a Markdown document:

```js
import { is } from 'very-small-parser/lib/markdown/is';

is('Hello __world__!');     // true
is('<b>Hello</b>!');        // false
```

Pretty-print MDAST back to text:

```js
import { markdown } from 'very-small-parser';
import { toText } from 'very-small-parser/lib/markdown/block/toText';

const mdast = markdown.block.parse('Hello __world__!');
const text = toText(mdast); // Hello __world__!
```

Convert MDAST to HAST (Markdown AST to HTML AST):

```js
import { markdown } from 'very-small-parser';
import { toHast } from 'very-small-parser/lib/markdown/block/toHast';
import { toText } from 'very-small-parser/lib/html/toText';

const mdast = markdown.block.parse('Hello __world__!');
const hast = toHast(mdast);
const html = toText(hast); // <p>Hello <strong>world</strong>!</p>
```


### HTML

Parse HTML to HAST (Hypertext Abstract Syntax Tree):

```js
import { html } from 'very-small-parser';

const ast = html.parse('<b>Hello</b> <i>world</i>!');
```

Pretty-print HAST to HTML:

```js
import { html } from 'very-small-parser';
import { toText } from 'very-small-parser/lib/html/toText';

const hast = html.parse('<b>Hello</b> <i>world</i>!');
const html = toText(hast); // '<b>Hello</b> <i>world</i>!'
```

Specify tabulation size for indentation when pretty-printing:

```js
import { html } from 'very-small-parser';
import { toText } from 'very-small-parser/lib/html/toText';

const tab = '  ';
const hast = html.parse('<div><b>Hello</b><i>world</i>!</div>', tab);
const html = toText(hast);
// <div>
//   <b>Hello</b>
//   <i>world</i>
//   !
// </div>
```

Convert HAST to MDAST (HTML AST to Markdown AST):

```js
import { html } from 'very-small-parser';
import { toMdast } from 'very-small-parser/lib/html/toMdast';
import { toText } from 'very-small-parser/lib/markdown/block/toText';

const hast = html.parse('<p><b>Hello</b> <i>world</i>!</p>');
const mdast = toMdast(hast);
const text = toText(mdast); // __Hello__ _world_!
```


### JSON-ML

JSON-ML is a simple way to represent HTML as JSON. For example, the HTML
`<b>Hello</b>` is represented as `['b', null, 'Hello']`. The first element is
the tag name, the second is the attributes, and the rest are children.

This package contains converters for JSON-ML to HAST and back. See the [`/src/html/json-ml`](./src/html/json-ml/) directory.

---
_Source: https://npm.io/package/very-small-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
