![mdast](https://cdn.rawgit.com/wooorm/mdast/master/logo.svg)
![Coverage Status](https://img.shields.io/coveralls/wooorm/mdast.svg?style=flat)
mdast is speedy Markdown parser (and stringifier) for multipurpose analysis (a syntax tree) in JavaScript. Node.JS and the browser. Lots of tests. 100% coverage.
Installation
npm:
$ npm install mdast
Component.js:
$ component install wooorm/mdast
Bower:
$ bower install mdast
Usage
See Nodes for information about returned objects.
var mdast = require('mdast');
var ast = mdast.parse('Some *emphasis*, **strongness**, and `code`.');
Yields:
{
"type" : "root",
"children" : [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "Some "
},
{
"type": "emphasis",
"children": [{
"type": "text",
"value": "emphasis"
}]
},
{
"type": "text",
"value": ", "
},
{
"type": "strong",
"children": [{
"type": "text",
"value": "strongness"
}]
},
{
"type": "text",
"value": ", and "
},
{
"type": "inlineCode",
"value": "code"
},
{
"type": "text",
"value": "."
}
]
}
]
}
And passing that document into mdast.stringify
:
mdast.stringify(ast);
Yields:
Some _emphasis_, **strongness**, and `code`.
API
Parameters:
value
(string
) — Markdown document;options
(Object
, null
, undefined
) — Optional options:
All options (including the options object itself) can be null
or undefined
to default to their default values.
Returns: An Object
. See Nodes for the AST specification.
Parameters:
ast
(Object
) — An AST as returned by mdast.parse;options
(Object
) — Optional options:
setext
(boolean
, default: false
). See Setext Headings;referenceLinks
(boolean
, default: false
). See Reference Links;referenceFootnotes
(boolean
, default: true
). See Inline Footnotes;fences
(boolean
, default: false
). See Fences;bullet
("-"
, "*"
, or "+"
, default: "-"
). See List Item Bullets;rule
("-"
, "*"
, or "_"
, default: "*"
). See Horizontal Rules;ruleRepetition
(number
, default: 3). See Horizontal Rules;ruleSpaces
(boolean
, default true
). See Horizontal Rules;strong
("_"
, or "*"
, default "*"
). See Emphasis Markers;emphasis
("_"
, or "*"
, default "_"
). See Emphasis Markers.
All options (including the options object itself) can be null
or undefined
to default to their default values.
Returns: A string
.
CLI
Install:
$ npm install --global mdast
Use:
Usage: mdast [options] file
Speedy Markdown parser/stringifier for multipurpose analysis
Options:
-h, --help output usage information
-v, --version output version number
-a, --ast output AST information
--options output available settings
-o, --option <option> specify settings
Usage:
# Note that bash does not allow reading/writing to the same through pipes
# Pass `Readme.md` through mdast
$ mdast Readme.md > Readme-new.md
# Pass stdin through mdast, with options
$ cat Readme.md | mdast -o "setext, bullet: *" > Readme-new.md
Benchmark
On a MacBook Air, it parser more than 3 megabytes of markdown per second, depending on how much markup v.s. plain text the document contains, and which language the document is in, that’s more than the entire works of Shakespeare, in under two seconds.
benchmarks * 76 fixtures (total: 50Kb markdown)
63 op/s » mdast.parse
145 op/s » mdast.stringify
License
This project was initially a fork of marked.
Copyright (c) 2011-2014, Christopher Jeffrey. (MIT License)
MIT © Titus Wormer