Package Exports
- mdast-zone
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mdast-zone) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
mdast-zone

MDAST utility to treat HTML comments as ranges. Useful in remark plugins.
Installation
npm:
npm install mdast-zoneUsage
Say we have the following file, example.md:
<!--foo start-->
Foo
<!--foo end-->And our script, example.js, looks as follows:
var vfile = require('to-vfile')
var remark = require('remark')
var zone = require('mdast-zone')
remark()
.use(plugin)
.process(vfile.readSync('example.md'), function(err, file) {
if (err) throw err
console.log(String(file))
})
function plugin() {
return transform
function transform(tree) {
zone(tree, 'foo', mutate)
}
function mutate(start, nodes, end) {
return [
start,
{type: 'paragraph', children: [{type: 'text', value: 'Bar'}]},
end
]
}
}Now, running node example yields:
<!--foo start-->
Bar
<!--foo end-->API
zone(tree, name, handler)
Search tree for comment ranges (“zones”).
Parameters
tree(Node) — Node to search for rangesname(string) — Name of ranges to search forhandler(Function) — Function invoked for each found range
function handler(start, nodes, end)
Invoked with the two markers that determine a range: the first start
and the last end, and the content inside.
Parameters
start(Node) — Start of range (an HTML comment node)nodes(Array.<Node>) — Nodes betweenstartandendend(Node) — End of range (an HTML comment node)
Returns
Array.<Node>? — List of nodes to replace start, nodes, and end
with, optional.
Contribute
See contributing.md in syntax-tree/mdast for ways to get
started.
This organisation has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.