Re: [SAC] ConditionFactory.createClassCondition

Le 21/05/2012 01:48, Bjoern Hoehrmann a écrit :
>> All I actually need is a way to parse and access CSS3 selectors. The
>> present tools seem to be incomplete so I decided to write my own
>> implementation. By using SAC as the API I thought others might benefit
>> from it, too. Though the API design (at least the Java version) doesn't
>> seem to be perfect, I rather would like to use some kind of common API
>> than to reinvent my own CSS parser wheel. However, the latter now seems
>> to be a better choice.
> There are probably better APIs to emulate than SAC, but I don't know
> anything particularily good or established, so rolling your own might
> be the best choice.

If you don’t want to invent your own wheel you can use mine :)

SAC did not look satisfying so I went with rolling my own API for 
tinycss. I think that the result is good, although I wouldn’t call it 
established. At least it works for me in WeasyPrint and CairoSVG.

tinycss for stylesheets: http://packages.python.org/tinycss/
cssselect for selectors: http://packages.python.org/cssselect/
Using the two together:
http://packages.python.org/tinycss/css3.html#selectors-3

The tokenizer in cssselect is slightly broken (see github #2 and #7), 
but this should be fixable.

This is all in Python, but hopefully if you use another language you can 
still get ideas from these projects.

-- 
Simon Sapin

Received on Monday, 21 May 2012 05:20:46 UTC