Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a CSS object model or CSS querying api for .net?

Tags:

c#

.net

css

dotless

Is there a library out there that will allow me to write the following kind of code, which parses CSS and returns a queryable object model

string input = "p, span { font-family: arial; }";
var cssRules = new Parser().Parse(input);
var rule = cssRules.Find(new Selector("p")).First();

Assert.That(rule.Attribute("font-family").Value, Is.Equal.To("arial"));

I've taken a look at dotless, downloaded their code and examined some of the relevant unit tests and fixtures. It looks promising but I can't quite work out how to use it to parse and query plain CSS.

like image 823
Edward Wilde Avatar asked Jul 25 '11 10:07

Edward Wilde


1 Answers

The closest I know is CssParser from jsonfx.net:

http://css-parser.googlecode.com/svn/trunk/CssParser/

You can parse any css and browse through selectors afterwards using StyleSheet property of CssParser

like image 69
michalczerwinski Avatar answered Sep 23 '22 01:09

michalczerwinski