1 | # ![mdast](https://cdn.rawgit.com/wooorm/mdast/master/logo.svg)
|
2 |
|
3 | [![Build Status](https://img.shields.io/travis/wooorm/mdast.svg)](https://travis-ci.org/wooorm/mdast) [![Coverage Status](https://img.shields.io/codecov/c/github/wooorm/mdast.svg)](https://codecov.io/github/wooorm/mdast) [![Inline docs](https://img.shields.io/badge/docs-A-brightgreen.svg)](http://inch-ci.org/github/wooorm/mdast)
|
4 |
|
5 | **mdast** is a markdown processor powered by plugins. Lots of tests. Node,
|
6 | io.js, and the browser. 100% coverage.
|
7 |
|
8 | **mdast** is not just another markdown to HTML compiler. It can generate,
|
9 | and reformat, markdown too. It’s powered by [plugins](doc/plugins.md) to do
|
10 | all kinds of things: [validate your markdown](https://github.com/wooorm/mdast-lint),
|
11 | [add links for GitHub references](https://github.com/wooorm/mdast-github), or
|
12 | [add a table of contents](https://github.com/wooorm/mdast-toc).
|
13 |
|
14 | The project contains both an extensive [JavaScript API](doc/mdast.3.md) for
|
15 | parsing, modifying, and stringifying markdown, and a friendly [Command Line
|
16 | Interface](doc/mdast.1.md) making it easy to validate, prepare, and compile
|
17 | markdown in a build step.
|
18 |
|
19 | ## Table of Contents
|
20 |
|
21 | * [Installation](#installation)
|
22 |
|
23 | * [Usage](#usage)
|
24 |
|
25 | * [API](#api)
|
26 |
|
27 | * [mdast.process(value, options?, done?)](#mdastprocessvalue-options-done)
|
28 | * [mdast.use(plugin, options?)](#mdastuseplugin-options)
|
29 |
|
30 | * [CLI](#cli)
|
31 |
|
32 | * [License](#license)
|
33 |
|
34 | ## Installation
|
35 |
|
36 | [npm](https://docs.npmjs.com/cli/install):
|
37 |
|
38 | ```bash
|
39 | npm install mdast
|
40 | ```
|
41 |
|
42 | [Read more about alternatives ways to install and use »](doc/getting-started.md).
|
43 |
|
44 | ## Usage
|
45 |
|
46 | Load dependencies:
|
47 |
|
48 | ```javascript
|
49 | var mdast = require('mdast');
|
50 | var html = require('mdast-html');
|
51 | var yamlConfig = require('mdast-yaml-config');
|
52 | ```
|
53 |
|
54 | Use plugins:
|
55 |
|
56 | ```javascript
|
57 | var processor = mdast().use(yamlConfig).use(html);
|
58 | ```
|
59 |
|
60 | Process the document:
|
61 |
|
62 | ```javascript
|
63 | var doc = processor.process([
|
64 | '---',
|
65 | 'mdast:',
|
66 | ' commonmark: true',
|
67 | '---',
|
68 | '',
|
69 | '2) Some *emphasis*, **strongness**, and `code`.'
|
70 | ].join('\n'));
|
71 | ```
|
72 |
|
73 | Yields:
|
74 |
|
75 | ```html
|
76 | <ol start="2">
|
77 | <li>Some <em>emphasis</em>, <strong>strongness</strong>, and <code>code</code>.</li>
|
78 | </ol>
|
79 | ```
|
80 |
|
81 | ## API
|
82 |
|
83 | This section only covers the interface you’ll use most often. See
|
84 | [**mdast**(3) documentation](doc/mdast.3.md) for a more complete description.
|
85 |
|
86 | ### [mdast](#api).process(value, [options](doc/mdastsetting.7.md)?, done?)
|
87 |
|
88 | Parse a markdown document, apply plugins to it, and compile it into
|
89 | something else.
|
90 |
|
91 | **Signatures**
|
92 |
|
93 | * `doc = mdast.process(value, options?, done?)`.
|
94 |
|
95 | **Parameters**
|
96 |
|
97 | * `value` (`string`) — Markdown document;
|
98 |
|
99 | * `options` (`Object`) — Settings:
|
100 |
|
101 | * `gfm` (`boolean`, default: `true`) — See [Github Flavoured Markdown](doc/mdastsetting.7.md#github-flavoured-markdown);
|
102 | * `yaml` (`boolean`, default: `true`) — See [YAML](doc/mdastsetting.7.md#yaml);
|
103 | * `commonmark` (`boolean`, default: `false`) — See [CommonMark](doc/mdastsetting.7.md#commonmark);
|
104 | * `footnotes` (`boolean`, default: `false`) — See [Footnotes](doc/mdastsetting.7.md#footnotes);
|
105 | * `pedantic` (`boolean`, default: `false`) — See [Pedantic](doc/mdastsetting.7.md#pedantic);
|
106 | * `breaks` (`boolean`, default: `false`) — See [Breaks](doc/mdastsetting.7.md#breaks);
|
107 | * `entities` (`boolean`, default: `false`) — See [Encoding Entities](doc/mdastsetting.7.md#encoding-entities);
|
108 | * `setext` (`boolean`, default: `false`) — See [Setext Headings](doc/mdastsetting.7.md#setext-headings);
|
109 | * `closeAtx` (`boolean`, default: `false`) — See [Closed ATX Headings](doc/mdastsetting.7.md#closed-atx-headings);
|
110 | * `looseTable` (`boolean`, default: `false`) — See [Loose Tables](doc/mdastsetting.7.md#loose-tables);
|
111 | * `spacedTable` (`boolean`, default: `true`) — See [Spaced Tables](doc/mdastsetting.7.md#spaced-tables);
|
112 | * `fence` (`"~"` or ``"`"``, default: ``"`"``) — See [Fence](doc/mdastsetting.7.md#fence);
|
113 | * `fences` (`boolean`, default: `false`) — See [Fences](doc/mdastsetting.7.md#fences);
|
114 | * `bullet` (`"-"`, `"*"`, or `"+"`, default: `"-"`) — See [List Item Bullets](doc/mdastsetting.7.md#list-item-bullets);
|
115 | * `listItemIndent` (`"tab"`, `"mixed"` or `"1"`, default: `"tab"`) — See [List Item Indent](doc/mdastsetting.7.md#list-item-indent);
|
116 | * `incrementListMarker` (`boolean`, default: `true`) — See [List Marker Increase](doc/mdastsetting.7.md#list-marker-increase);
|
117 | * `rule` (`"-"`, `"*"`, or `"_"`, default: `"*"`) — See [Horizontal Rules](doc/mdastsetting.7.md#horizontal-rules);
|
118 | * `ruleRepetition` (`number`, default: `3`) — See [Horizontal Rules](doc/mdastsetting.7.md#horizontal-rules);
|
119 | * `ruleSpaces` (`boolean`, default `true`) — See [Horizontal Rules](doc/mdastsetting.7.md#horizontal-rules);
|
120 | * `strong` (`"_"`, or `"*"`, default `"*"`) — See [Emphasis Markers](doc/mdastsetting.7.md#emphasis-markers);
|
121 | * `emphasis` (`"_"`, or `"*"`, default `"_"`) — See [Emphasis Markers](doc/mdastsetting.7.md#emphasis-markers).
|
122 | * `position` (`boolean`, default: `true`) — See [Position](doc/mdastsetting.7.md#position);
|
123 |
|
124 | * `done` (`function(Error?, string?)`) — Callback invoked when the output
|
125 | is generated with either an error, or a result. Only strictly needed when
|
126 | async plugins are used.
|
127 |
|
128 | All options (including the options object itself) can be `null` or `undefined`
|
129 | to default to their default values.
|
130 |
|
131 | **Returns**
|
132 |
|
133 | `string` or `null`: A document. Formatted in markdown by default, or in
|
134 | whatever a plugin generates.
|
135 | The result is `null` if a plugin is asynchronous, in which case the callback
|
136 | `done` should’ve been passed (don’t worry: plugin creators make sure you know
|
137 | its async).
|
138 |
|
139 | ### [mdast](#api).use([plugin](doc/plugins.md#plugins), options?)
|
140 |
|
141 | Change the way [`mdast`](#api) works by using a [`plugin`](doc/plugins.md).
|
142 |
|
143 | **Signatures**
|
144 |
|
145 | * `processor = mdast.use(plugin, options?)`;
|
146 | * `processor = mdast.use(plugins)`.
|
147 |
|
148 | **Parameters**
|
149 |
|
150 | * `plugin` (`Function`) — A [**Plugin**](doc/plugins.md);
|
151 | * `plugins` (`Array.<Function>`) — A list of [**Plugin**](doc/plugins.md)s;
|
152 | * `options` (`Object?`) — Passed to plugin. Specified by its documentation.
|
153 |
|
154 | **Returns**
|
155 |
|
156 | `Object`: an instance of MDAST: The returned object functions just like
|
157 | **mdast** (it has the same methods), but caches the `use`d plugins. This
|
158 | provides the ability to chain `use` calls to use multiple plugins, but
|
159 | ensures the functioning of the **mdast** module does not change for other
|
160 | dependents.
|
161 |
|
162 | ## CLI
|
163 |
|
164 | Install:
|
165 |
|
166 | ```bash
|
167 | npm install --global mdast
|
168 | ```
|
169 |
|
170 | Use:
|
171 |
|
172 | ```text
|
173 | Usage: mdast [options] <file|dir ...>
|
174 |
|
175 | Markdown processor powered by plugins
|
176 |
|
177 | Options:
|
178 |
|
179 | -h, --help output usage information
|
180 | -V, --version output the version number
|
181 | -o, --output [path] specify output location
|
182 | -c, --config-path <path> specify configuration location
|
183 | -i, --ignore-path <path> specify ignore location
|
184 | -s, --setting <settings> specify settings
|
185 | -u, --use <plugins> use transform plugin(s)
|
186 | -e, --ext <extensions> specify extensions
|
187 | -w, --watch watch for changes and reprocess
|
188 | -a, --ast output AST information
|
189 | -q, --quiet output only warnings and errors
|
190 | -S, --silent output only errors
|
191 | -f, --frail exit with 1 on warnings
|
192 | --file-path <path> specify file path to process as
|
193 | --no-stdout disable writing to stdout
|
194 | --no-color disable color in output
|
195 | --no-rc disable configuration from .mdastrc
|
196 | --no-ignore disable ignore from .mdastignore
|
197 |
|
198 | Usage:
|
199 |
|
200 | # Process `readme.md`
|
201 | $ mdast readme.md -o readme-new.md
|
202 |
|
203 | # Pass stdin through mdast, with settings, to stdout
|
204 | $ mdast -s "setext: true, bullet: \"*\"" < readme.md > readme-new.md
|
205 |
|
206 | # Use a plugin (with options)
|
207 | $ npm install mdast-toc
|
208 | $ mdast --use toc=heading:"contents" readme.md -o
|
209 |
|
210 | # Rewrite markdown in a directory
|
211 | $ mdast . -o
|
212 |
|
213 | See also: man 1 mdast, man 3 mdast, man 3 mdastplugin,
|
214 | man 5 mdastrc, man 5 mdastignore, man 7 mdastsetting,
|
215 | man 7 mdastconfig, man 7 mdastnode, man 7 mdastplugin.
|
216 | ```
|
217 |
|
218 | ## License
|
219 |
|
220 | [MIT](LICENSE) © [Titus Wormer](http://wooorm.com)
|
221 |
|
222 | > This project was initially a fork of [marked](https://github.com/chjj/marked).
|
223 |
|
224 | Copyright (c) 2011-2014, Christopher Jeffrey. (MIT License)
|