unified

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

Package:hast-util-from-selector@1.0.0

  1. Dependencies:3·Dependents:1
  2. hast utility to parse CSS selectors to hast nodes
  1. hast 78
  2. rehype 74
  3. html 61
  4. parse 17
  5. css 9
  6. hyperscript 5
  7. selector 4
  8. 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

Usage

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, organisation, or community you agree to abide by its terms.

License

MIT © Titus Wormer