Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attribute selectors not fully parsed #6

Open
cvrebert opened this issue Jul 19, 2015 · 4 comments
Open

Attribute selectors not fully parsed #6

cvrebert opened this issue Jul 19, 2015 · 4 comments

Comments

@cvrebert
Copy link

Currently, the parse tree doesn't include full details for attribute selectors. For example, [att*=val] is parsed into:

{"type":"selectors","nodes":[
  {
    "type":"selector",
    "nodes":[
      {
        "type":"attribute",
        "content":"att*=val"
      }
    ]
  }
]}

It would be better if the "content" was further parsed, so we could get something like:

{"type":"selectors","nodes":[
  {
    "type":"selector",
    "nodes":[
      {
        "type":"attribute",
        "name":"att",
        "operator":"*=",
        "content":"val"
      }
    ]
  }
]}
@cvrebert
Copy link
Author

The ASCII-case-insensitive attribute value flag (e.g. [type=radio i]) also needs to be accounted for.

@iddan
Copy link

iddan commented Apr 9, 2017

Any progress with this?

@cvrebert
Copy link
Author

cvrebert commented Apr 9, 2017

@iddan
Copy link

iddan commented Apr 9, 2017

Here is a RegExp that I've been working on to parse attribute selectors.

/^\s*((?:\\.|[A-Za-z_\-\u{00a0}-\u{10ffff}])(?:\\.|[A-Za-z_\-0-9\u{00a0}-\u{10ffff}])*)(?:\s*(=|~=|\|=|\^=|\$=|\*=)\s*"?(.+?)"?)?\s*(i)?\s*$/u

$1 - name
$2 - operator (i.e =)
$3 - value
$4 - ASCII-case-insensitive attribute value flag

BUGS

  • can work with syntax errors
  • when omitting quotes captures everything before whitespace and i as value

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants