Package Exports
- mdast-util-heading-range
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-util-heading-range) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
mdast-util-heading-range

Markdown heading as ranges in MDAST.
Installation
npm:
npm install mdast-util-heading-rangeUsage
Say we have the following file, example.md:
# Foo
Bar.
# BazAnd our script, example.js, looks as follows:
var vfile = require('to-vfile');
var remark = require('remark');
var heading = require('mdast-util-heading-range');
remark()
.use(plugin)
.process(vfile.readSync('example.md'), function (err, file) {
if (err) throw err;
console.log(String(file));
});
function plugin() {
return transformer;
function transformer(tree) {
heading(tree, 'foo', mutate);
}
function mutate(start, nodes, end) {
return [
start,
{type: 'paragraph', children: [{type: 'text', value: 'Qux.'}]},
end
];
}
}Now, running node example yields:
# Foo
Qux.
# BazAPI
heading(node, test, onrun)
Transform part of a document without affecting other parts, by changing
a section: a heading which passes test, until the next heading of the
same or lower depth, or the end of the document.
Parameters
node(Node) — Node to searchtest(string,RegExp,function(string, Node): boolean) — Heading to look for. Whenstring, wrapped innew RegExp('^(' + value + ')$', 'i'); whenRegExp, wrapped infunction (value) {expression.test(value)}onrun(Function)
function onrun(start, nodes, end?, scope)
Callback invoked when a range is found.
Parameters
start(Heading) — Start of rangenodes(Array.<Node>) — Nodes betweenstartandendend(Heading?) — End of range, if anyscope(Object):parent(Node) — Parent of the rangestart(number) — Index ofstartinparentend(number?) — Index ofendinparent