unist-util-visit-children

2018-11-13 admin

unist-util-visit-children是什么

什么是unist-util-visit-children,Unist utility to visit direct children of a parent

unist-util-visit-children使用教程帮助文档

unist-util-visit-children Build Status Coverage Status

Unist direct child visitor.

Installation

npm:

npm install unist-util-visit-children

Usage

var remark = require('remark')
var visitChildren = require('unist-util-visit-children')

var visit = visitChildren(console.log)

remark()
  .use(plugin)
  .processSync('Some _emphasis_, **importance**, and `code`.')

function plugin() {
  return transformer
  function transformer(tree) {
    visit(tree.children[0])
  }
}

Yields:

{ type: 'text', value: 'Some ' }
{ type: 'emphasis',
  children: [ { type: 'text', value: 'emphasis' } ] }
{ type: 'text', value: ', ' }
{ type: 'strong',
  children: [ { type: 'text', value: 'importance' } ] }
{ type: 'text', value: ', and ' }
{ type: 'inlineCode', value: 'code' }
{ type: 'text', value: '.' }

API

visit = visitChildren(visitor)

Wrap visitor to be invoked for each child in the node given to visit.

function visitor(child, index, parent)

Invoked if visit is called on a parent node for each child in parent.

function visit(parent)

Invoke the bound visitor for each child in parent (Node).

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

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-45304.html

文章标题:unist-util-visit-children

回到顶部