How to use the css-select/lib/attributes.rules function in css-select

To help you get started, we’ve selected a few css-select examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github substance / substance / dom / _vendor.js View on Github external
import ElementType from 'domelementtype'
import cssSelect from 'css-select'
import DomUtils from 'domutils'
import attributes from 'css-select/lib/attributes'
import Parser from 'htmlparser2/lib/Parser'
import domSerializer from './_domSerializer'

// monkey patching css-select/lib/attributes to reflect difference in how classes are stored
// Note: in XNode classes are stored in a Set instead of a string
const _elementRule = attributes.rules.element
attributes.rules.element = function(next, data) {
  if (data.name === 'class') {
    let value = data.value
    if (/\s/.test(value)) return function() { return false }
    return function clazz(elem) {
      let classes = elem.classes
      return classes && classes.has(value) && next(elem)
    }
  } else {
    return _elementRule(next, data)
  }
}

Parser.prototype.oncdata = function(value){
  this._updatePosition(1);

  if(this._options.xmlMode){
github substance / substance / dom / _vendor.js View on Github external
import ElementType from 'domelementtype'
import cssSelect from 'css-select'
import DomUtils from 'domutils'
import attributes from 'css-select/lib/attributes'
import Parser from 'htmlparser2/lib/Parser'
import domSerializer from './_domSerializer'

// monkey patching css-select/lib/attributes to reflect difference in how classes are stored
// Note: in XNode classes are stored in a Set instead of a string
const _elementRule = attributes.rules.element
attributes.rules.element = function(next, data) {
  if (data.name === 'class') {
    let value = data.value
    if (/\s/.test(value)) return function() { return false }
    return function clazz(elem) {
      let classes = elem.classes
      return classes && classes.has(value) && next(elem)
    }
  } else {
    return _elementRule(next, data)
  }
}

Parser.prototype.oncdata = function(value){
  this._updatePosition(1);

css-select

a CSS selector compiler/engine

BSD-2-Clause
Latest version published 2 years ago

Package Health Score

82 / 100
Full package analysis