Closed 0x2b3bfa0 closed 3 months ago
It turns out that unist-util-visit takes a Visitor function, that may optionally return an Index to "specify the sibling to traverse after [the current] node is traversed", but Array.prototype.push "returns the new length of the array", causing an erratic tree traversal.
unist-util-visit
Visitor
Index
node
Array.prototype.push
const remark = require('remark'); const visit = require('unist-util-visit'); const report = ` # Heading 1 [![description](https://img.shields.io/badge/...)](https://studio.iterative.ai/team/...) ## Heading 2 ![one](./one) ![two](./two) ![three](./three) `; function plugin(tree) { const nodes = []; // The visitor function returns the result of calling nodes.push() visit(tree, ['definition', 'image', 'link'], (node) => nodes.push(node)); nodes.map(({url}) => console.log(url)); } remark().use(() => plugin).process(report);
https://studio.iterative.ai/team/... https://img.shields.io/badge/... ./one ./three ./three
It turns out that
unist-util-visit
takes aVisitor
function, that may optionally return anIndex
to "specify the sibling to traverse after [the current]node
is traversed", butArray.prototype.push
"returns the new length of the array", causing an erratic tree traversal.Minimal example