css-select-codsen-parser
v0.6.0
Published
An adapter for `css-select` to allow querying of `codsen-parser` generated trees.
Downloads
13
Readme
css-select-codsen-parser
An adapter for css-select
to allow querying of codsen-parser
generated trees.
Install
$ npm install css-select-codsen-parser
Usage
To use this adapter, first you must run the AST through prepare
.
const parse = require("codsen-parser");
const CSSselect = require("css-select");
const { prepare, adapter } = require("css-select-codsen-parser");
const ast = prepare(
parse(`
<div id="greeting">
Hello <span class="name">Alice</span>
</div>
`)
);
const nodes = cssSelect("#greeting .name", ast, { adapter });
// => [ { type: 'tag', start: 37, end: 56, value: '<span class="name">'... ]
API
prepare(ast)
Note: This method modifies the AST directly.
Accepts an AST generated by codsen-parser
.
Returns the same AST.
adapter
css-select
adapter. See documentation on how to use a custom adapter.