Skip to content

Commit

Permalink
Add support for passing options through to mdast-util-to-nlcst
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 3, 2017
1 parent d1be63d commit 9d9b5d3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ module.exports = remark2retext;
* with the new NLCST tree (bridge-mode).
* If a parser is given, returns the NLCST tree: further
* plug-ins run on that tree (mutate-mode). */
function remark2retext(destination) {
function remark2retext(destination, options) {
var fn = destination && destination.run ? bridge : mutate;
return fn(destination);
return fn(destination, options);
}

/* Mutate-mode. Further transformers run on the NLCST tree. */
function mutate(parser) {
function mutate(parser, options) {
return transformer;
function transformer(node, file) {
return mdast2nlcst(node, file, parser);
return mdast2nlcst(node, file, parser, options);
}
}

/* Bridge-mode. Runs the destination with the new NLCST
* tree. */
function bridge(destination) {
function bridge(destination, options) {
return transformer;
function transformer(node, file, next) {
var Parser = destination.freeze().Parser;
var tree = mdast2nlcst(node, file, Parser);

destination.run(tree, file, function (err) {
var tree = mdast2nlcst(node, file, Parser, options);
destination.run(tree, file, done);
function done(err) {
next(err);
});
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"index.js"
],
"dependencies": {
"mdast-util-to-nlcst": "^3.0.0"
"mdast-util-to-nlcst": "^3.2.0"
},
"devDependencies": {
"browserify": "^14.0.0",
Expand Down
10 changes: 9 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ example.md

## API

### `origin.use(remark2retext, destination)`
### `origin.use(remark2retext, destination[, options])`

Either bridge or mutate from [**remark**][remark] ([MDAST][]) to
[**retext**][retext] ([NLCST][]).
Expand All @@ -68,6 +68,10 @@ If a parser (such as [**parse-latin**][latin], [**parse-english**][english],
or [**parse-dutch**][dutch]) is given, passes the tree to further
plug-ins (mutate-mode).

###### `options`

Passed to [`mdast-util-to-nlcst`][to-nlcst].

## Related

* [`rehype-retext`](https://github.com/wooorm/rehype-retext)
Expand All @@ -76,6 +80,8 @@ plug-ins (mutate-mode).
— Transform markdown to HTML
* [`rehype-remark`](https://github.com/wooorm/rehype-remark)
— Transform HTML to markdown
* [`mdast-util-to-nlcst`][to-nlcst]
— Underlying algorithm

## License

Expand Down Expand Up @@ -114,3 +120,5 @@ plug-ins (mutate-mode).
[english]: https://github.com/wooorm/parse-english

[dutch]: https://github.com/wooorm/parse-dutch

[to-nlcst]: https://github.com/syntax-tree/mdast-util-to-nlcst

0 comments on commit 9d9b5d3

Please sign in to comment.