Skip to content

jlevy/unist-util-visit

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unist-util-visit Build Status Coverage Status

Unist node visitor. Useful when working with remark, retext, or rehype.

Installation

npm:

npm install unist-util-visit

Usage

var remark = require('remark');
var visit = require('unist-util-visit');

var tree = remark.parse('Some _emphasis_, **importance**, and `code`.');

visit(tree, 'text', visitor);

function visitor(node) {
  console.log(node);
}

Yields:

{ type: 'text', value: 'Some ' }
{ type: 'text', value: 'emphasis' }
{ type: 'text', value: ', ' }
{ type: 'text', value: 'importance' }
{ type: 'text', value: ', and ' }
{ type: 'text', value: '.' }

API

visit(node[, test], visitor[, reverse])

Visit nodes. Optionally filtering nodes. Optionally in reverse.

Parameters
  • node (Node) — Node to search
  • test (Test, optional) — Node type or other is-compatible test
  • visitor (Function) — Visitor invoked when a node is found
  • reverse (boolean, default: false) — When falsey, checking starts at the first child and continues through to later children. When truthy, this is reversed. This does not mean checking starts at the deepest node and continues on to the highest node

stop? = visitor(node, index, parent)

Invoked when a node (matching test, if given) is found.

Parameters
  • node (Node) — Found node
  • index (number?) — Position of node in parent
  • parent (Node?) — Parent of node
Returns

boolean? - When false, visiting is immediately stopped.

Related

License

MIT © Titus Wormer

About

Utility to recursively walk over Unist nodes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%