https://github.com/mkdoc/mkast
Transform commonmark nodes
https://github.com/mkdoc/mkast
Last synced: about 1 year ago
JSON representation
Transform commonmark nodes
- Host: GitHub
- URL: https://github.com/mkdoc/mkast
- Owner: mkdoc
- Archived: true
- Created: 2016-03-13T01:54:42.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-12-05T02:05:37.000Z (over 9 years ago)
- Last Synced: 2025-04-22T23:17:56.410Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 93.8 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Tree
[](https://travis-ci.org/mkdoc/mkast)
[](https://npmjs.org/package/mkast)
[](https://coveralls.io/github/mkdoc/mkast?branch=master)
> Converts nodes to and from JSON
Transforms [commonmark][] nodes to and from JSON for piping between processes.
## Install
```
npm i mkast
```
---
- [Install](#install)
- [Usage](#usage)
- [API](#api)
- [parser](#parser)
- [deserialize](#deserialize)
- [serialize](#serialize)
- [License](#license)
---
## Usage
Serialize [commonmark][] nodes to line-delimited JSON:
```javascript
var mkast = require('mkast')
, ast = mkast.parse('# Title\n @include file.md ?>');
mkast.serialize(ast).pipe(process.stdout);
```
For more information see the [api docs](#api).
## API
### parser
```javascript
parser(stream[, cb])
```
Parse line-delimited JSON to vanilla objects.
When a callback function is given it is added as a listener for
the `error` and `finish` events on the parser stream.
Returns the parser stream.
* `stream` Object input stream.
* `cb` Function callback function.
### deserialize
```javascript
deserialize([stream][, cb])
```
Deserialize line-delimited JSON to commonmark nodes.
When a callback function is given it is added as a listener for
the `error` and `eof` events on the deserializer stream.
The `eof` event can fire multiple times so the callback may be called
multiple times.
Returns the deserializer stream.
* `stream` Object input stream.
* `cb` Function callback function.
### serialize
```javascript
serialize(node[, opts][, cb])
```
Serialize a commonmark AST node to line-delimited JSON.
When the node is of the `document` type it's direct descendants are
detached from the document and streamed as independent lines. So that
consumers of the stream will know when the document ends a node
with an `eof` type is sent to indicate the end of file (EOF).
When injecting documents into a stream it may be desirable to disable
this behaviour, to do so use:
```javascript
{eof: false}
```
When a callback function is given it is added as a listener for
the `error` and `finish` events on the serializer stream.
Returns the serializer stream.
* `node` Object input AST node.
* `opts` Object processing options.
* `cb` Function callback function.
## License
MIT
---
Created by [mkdoc](https://github.com/mkdoc/mkdoc) on April 2, 2016
[mkdoc]: https://github.com/mkdoc/mkdoc
[commonmark]: http://commonmark.org
[jshint]: http://jshint.com
[jscs]: http://jscs.info