Utility to recursively walk over unist nodes
Clone or download

readme.md

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(tree[, test], visitor[, reverse])

This function works exactly the same as unist-util-visit-parents, but visitor has a different signature.

next? = visitor(node, index, parent)

Instead of being passed an array of ancestors, visitor is invoked with the node’s index and its parent.

Otherwise the same as unist-util-visit-parents.

Related

Contribute

See contributing.md in syntax-tree/unist 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.

License

MIT © Titus Wormer