views:

63

answers:

2

Anybody know of snippet that will parse a CSS3 selector like this:

"form#network_template[method='put'][action='#form_{keyname}']"

to this:

{
  tag: "form",
  id: "network_template",
  method: "put",
  action: "#form_{keyname}"
}

or this:

<form id="network_template" method="put" action="#form_{keyname}">
+2  A: 

Sizzle is used underneath jQuery. And there is also Peppy. Newer versions have at least some CSS3 selector support. YMMV.

Google searches reveal interesting leads.

pst
I wasn't looking for an engine, but a parser. Someone had "clarified" my title.
CoolAJ86
For reference: AFAIK Sizzle doesn't support all possible selectors - by design.
DanMan
+4  A: 

Assuming you meant to ask for a CSS3 selector parser in the title, Slick, used in Mootools, may do the job; from the github page:

Slick.parse("h1, h2, ul > li, .things")

{
"raw": "h1, h2, ul > li, .things",
"expressions": [
    [{ "combinator":" ", "tag": "h1" }],
    [{ "combinator":" ", "tag": "h2" }],
    [{ "combinator":" ", "tag": "ul" }, { "combinator": ">", "tag": "li" }],
    [{ "combinator":" ", "tag": "*", "classList": ["things"], "classes": [{"value": "things", "regexp":RegExp }] }]
]
}

Mootools can also create an element with appropriate attributes straight from a selector.

Angiosperm
This is exactly what I was trying to find, thanks.
CoolAJ86