I like the new function cssutils.parseStyle() for parsing HTML style
attributes. I have been using:
cssutils.parseString(u"a{{{}}}".format(value))
However I would like to be able to replace URLs in the generated
CSSStyleDeclaration, and cssutils.replaceUrls() doesn't seem to accept a
CSSStyleDeclaration object as argument.
Would it make sense to extend cssutils.replaceUrls() so that I can call
it with a CSSStyleDeclaration argument?
Servus,
Walter
> hi Walter,
>
>> I like the new function cssutils.parseStyle() for parsing HTML style
>> attributes. I have been using:
>>
>> cssutils.parseString(u"a{{{}}}".format(value))
>>
>> However I would like to be able to replace URLs in the generated
>> CSSStyleDeclaration, and cssutils.replaceUrls() doesn't seem to accept a
>> CSSStyleDeclaration object as argument.
>>
>> Would it make sense to extend cssutils.replaceUrls() so that I can call
>> it with a CSSStyleDeclaration argument?
>
> This should be pretty easy. As I am in the process of changing quite a
> lot I could add this for the next alpha release (this month). So you
> suggest::
>
> cssutils.replaceUrls(CSSStyleDeclaration(...))
>
> instead of the now required CSSStyleSheet argument?
Exactly.
> One could even
> consider
>
> cssutils.replaceUrls(style=styleAttributeString)
>
> but maybe it is too much in a single function...
IMHO this is too much. And it is unsymmetric. replaceUrls() does the
parsing, but the result isn't serialized again.
> thanks
> Christof
>
> P.S.: Obviously not much traffic here, I almost thought about closing
> this group all together. Any thoughts?
As long as there's not much effort for managing the mailing list (and
there are subscribers ;)) you should keep it open.
Servus,
Walter
> I actually implemented this in trunk. Please check it out. (No release
> yet, maybe today or in the next week)
Works perfectly, however I'm wondering why you're using:
type(sheetOrStyle) != css.CSSStyleDeclaration
instead of
not isinstance(sheetOrStyle, css.CSSStyleDeclaration)
Servus,
Walter
not isinstance( seems simpler. guess I just change it, thanks!
isinstance() is the canonical approach.
> not isinstance( seems simpler. guess I just change it, thanks!
The difference between the two test is that the test via type() doesn't
handle subclasses, isinstance() does.
Servus,
Walter