GithubHelp home page GithubHelp logo

gibson042 / unist-util-visit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from syntax-tree/unist-util-visit

0.0 3.0 0.0 42 KB

Utility to recursively walk over Unist nodes

Home Page: https://unifiedjs.github.io

License: MIT License

JavaScript 100.00%

unist-util-visit's Introduction

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[, type], visitor[, reverse])

Visit nodes. Optionally by node type. Optionally in reverse.

Parameters
  • node (Node) — Node to search
  • type (string, optional) — Node type
  • 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 (when type is given, matching type) 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

unist-util-visit's People

Contributors

wooorm avatar eush77 avatar greenkeeperio-bot avatar

Watchers

James Cloos avatar Richard Gibson avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.