Select unist nodes with CSS-like selectors.
View the list of supported selectors »
npm:
npm install unist-util-select
Select the first node matching selector
in the given tree
(could be the
tree itself).
Returns the found node, if any.
Throws an error if node is not found or not unique.
Say we have the following file, example.md
:
1. Step 1.
2. TODO Step 2.
3. Step 3.
1. TODO Step 3.1.
2. Step 3.2.
3. TODO Step 3.3.
And our script, example.js
, looks as follows:
var fs = require('fs')
var remark = require('remark')
var select = require('unist-util-select')
var tree = remark().parse(fs.readFileSync('example.md'))
var step = select.one(tree, 'list text[value*=3.2]')
console.log(step)
Now, running node example
yields:
{ type: 'text', value: 'Step 3.2.' }
Select all nodes matching selector
in the given tree
(could include the
tree itself).
Returns the found nodes, if any.
Say we have the following file, example.md
:
1. Step 1.
2. TODO Step 2.
3. Step 3.
1. TODO Step 3.1.
2. Step 3.2.
3. TODO Step 3.3.
And our script, example.js
, looks as follows:
var fs = require('fs')
var remark = require('remark')
var select = require('unist-util-select')
var tree = remark().parse(fs.readFileSync('example.md'))
var todos = select(tree, 'list text[value*=TODO]')
console.log(todos)
Now, running node example
yields:
[ { type: 'text',
value: 'TODO Step 2.' },
{ type: 'text',
value: 'TODO Step 3.1.' },
{ type: 'text',
value: 'TODO Step 3.3.' } ]
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.
MIT © Eugene Sharygin