Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork0
Small, no dependencies, Markdown, HTML, and inline CSS parser. Just 4KB, available as ESM module from CDN.
License
streamich/very-small-parser
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
- JavaScript parser for Markdown, HTML, and inline CSS.
- Tiny, just over 4KB.
- Runs in browser and Node.js.
- No dependencies.
- Markdown is parsed intoMDAST (Markdown Abstract Syntax Tree).
- HTML is parsed intoHAST (Hypertext Abstract Syntax Tree).
On the web you can simply import the module using a script tag.
Using ESM.sh:
<scripttype="module">import{markdown}from'//esm.sh/very-small-parser';constast=markdown.block.parsef('Hello __world__!');console.log(ast);</script>
Using jsDelivr:
<scripttype="module">import{markdown}from'//esm.run/very-small-parser';constast=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:
npm install very-small-parser
Parse Markdown document (block elements):
import{markdown}from'very-small-parser';constast=markdown.block.parsef('Hello __world__!');
Parse Markdown inline markup only:
constast=markdown.inline.parse('Hello __world__!');
Detect if text is likely to be a Markdown document:
import{is}from'very-small-parser/lib/markdown/is';is('Hello __world__!');// trueis('<b>Hello</b>!');// false
Pretty-print MDAST back to text:
import{markdown}from'very-small-parser';import{toText}from'very-small-parser/lib/markdown/block/toText';constmdast=markdown.block.parse('Hello __world__!');consttext=toText(mdast);// Hello __world__!
Convert MDAST to HAST (Markdown AST to HTML AST):
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';constmdast=markdown.block.parse('Hello __world__!');consthast=toHast(mdast);consthtml=toText(hast);// <p>Hello <strong>world</strong>!</p>
Parse HTML to HAST (Hypertext Abstract Syntax Tree):
import{html}from'very-small-parser';constast=html.parse('<b>Hello</b> <i>world</i>!');
Pretty-print HAST to HTML:
import{html}from'very-small-parser';import{toText}from'very-small-parser/lib/html/toText';consthast=html.parse('<b>Hello</b> <i>world</i>!');consthtml=toText(hast);// '<b>Hello</b> <i>world</i>!'
Specify tabulation size for indentation when pretty-printing:
import{html}from'very-small-parser';import{toText}from'very-small-parser/lib/html/toText';consttab=' ';consthast=html.parse('<div><b>Hello</b><i>world</i>!</div>',tab);consthtml=toText(hast);// <div>// <b>Hello</b>// <i>world</i>// !// </div>
Convert HAST to MDAST (HTML AST to Markdown AST):
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';consthast=html.parse('<p><b>Hello</b> <i>world</i>!</p>');constmdast=toMdast(hast);consttext=toText(mdast);// __Hello__ _world_!
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 isthe 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 directory.
About
Small, no dependencies, Markdown, HTML, and inline CSS parser. Just 4KB, available as ESM module from CDN.
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.