Unist node inspector.
npm:
npm install unist-util-inspect
component install wooorm/unist-util-inspect
bower install unist-util-inspect
Duo:
var inspect = require('wooorm/unist-util-inspect');
unist-util-inspect is also available for bower, component, duo, and for AMD, CommonJS, and globals (uncompressed and compressed).
var retext = require('retext');
var inspect = require('unist-util-inspect');
retext().use(function () {
return function (cst) {
console.log(inspect(cst));
}
}).process('Some simple text.');
Yields:
RootNode[1] (1:1-1:18, 0-17)
└─ ParagraphNode[1] (1:1-1:18, 0-17)
└─ SentenceNode[6] (1:1-1:18, 0-17)
├─ WordNode[1] (1:1-1:5, 0-4)
│ └─ TextNode: "Some" (1:1-1:5, 0-4)
├─ WhiteSpaceNode: " " (1:5-1:6, 4-5)
├─ WordNode[1] (1:6-1:12, 5-11)
│ └─ TextNode: "simple" (1:6-1:12, 5-11)
├─ WhiteSpaceNode: " " (1:12-1:13, 11-12)
├─ WordNode[1] (1:13-1:17, 12-16)
│ └─ TextNode: "text" (1:13-1:17, 12-16)
└─ PunctuationNode: "." (1:17-1:18, 16-17)
inspect(node)
By default, color support is enabled on node and turned off anywhere else. See below on how to change that.
Parameters
node
(Node
).
Returns string
— String representing node
.
Where style
is either color
or noColor
.
To explicitly add or remove ANSI sequences, use either inspect.color(node)
or inspect.noColor(node)
.