unified

Project: syntax-tree/hast-util-from-selector

Package: hast-util-from-selector@1.0.1

  1. Dependencies: 3·Dependents: 1
  2. hast utility to parse CSS selectors to hast nodes
  1. util 118
  2. utility 114
  3. unist 110
  4. html 110
  5. hast 60
  6. hast-util 40
  7. parse 22
  8. css 10
  9. hyperscript 5
  10. selector 4
  11. svg 2

hast-util-from-selector

Build Coverage Downloads Size Sponsors Backers Chat

hast utility to create nodes from an advanced CSS selector.

Install

npm:

npm install hast-util-from-selector

Use

var from = require('hast-util-from-selector')

console.log(from('p svg[viewbox=0 0 10 10] circle[cx=10][cy=10][r=10]'))

Yields:

{
  type: 'element',
  tagName: 'p',
  properties: {},
  children: [
    {
      type: 'element',
      tagName: 'svg',
      properties: {viewBox: '0 0 10 10'},
      children: [
        {
          type: 'element',
          tagName: 'circle',
          properties: {cx: '10', cy: '10', r: '10'},
          children: []
        }
      ]
    }
  ]
}

API

fromSelector([selector][, options])

Create one or more element nodes from a CSS selector.

Parameters
Returns

Element.

Support

Security

Use of from-selector can open you up to a cross-site scripting (XSS) attack as values are injected into the syntax tree.

Either do not use user input in from-selector or use hast-util-santize.

Contribute

See contributing.md in syntax-tree/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer