retext-visit
retext node visitor.
Installation
npm:
$ npm install retext-visit
Component:
$ component install wooorm/retext-visit
Bower:
$ bower install retext-visit
Usage
var Retext,
retext,
inspect,
visit;
Retext = require('retext');
visit = require('retext-visit');
inspect = require('retext-inspect');
retext = new Retext().use(inspect).use(visit);
API
Node#visit(function(Node): boolean?)
retext.parse('A simple English sentence.', function (err, tree) {
if (err) throw err;
tree.head.head.visit(function (node) {
console.log(node);
});
});
Invoke callback
for every descendant of the operated on context.
callback
(function(Node): boolean?
): Visitor. Stops visiting when it returns false
.
Node#visit(type, callback)
retext.parse('A simple English sentence.', function (err, tree) {
if (err) throw err;
tree.visit(tree.WORD_NODE, function (node) {
console.log(node);
});
});
Invoke callback
for every descendant of the context of type
.
type
: Type of visited nodes.callback
(function(Node): boolean?
): Visitor. Stops visiting when the return value is false
.
License
MIT © Titus Wormer