I can't see how to get from a rule to a set of properties?
This is my code so far.
Any help appreciated.
I want to get to
http://cssutils.googlecode.com/svn/trunk/docs/html/docs/css.html#cssutils.css.Property.cssText
a 'CSSStyleDeclaration/ think.
TIA, DaveP
#class cssutils.css.CSSRuleList(*ignored)
#
#
def checkrules(sheet):
nrules = sheet.cssRules.length
for item in range(0 , nrules):
rule = sheet.cssRules[item]
print rule.type, rule.typeString,
print rule.cssText
#
# Check a list of stylesheets
#
def ckSS(list):
for item in list:
parser=cssutils.CSSParser()
sheet = parser.parseFile(item,'utf-8')
print "******************* Checking %s **********************" % item
checkrules(sheet)
#
# List of stylesheets
#
ssList=['../css/f.css','../css/t.cake.css','../css/t.comments.css','../css/t.generic.css',]
ckSS(ssList)
--
Dave Pawson
XSLT XSL-FO FAQ.
Docbook FAQ.
http://www.dpawson.co.uk
Take a look at http://code.reddit.com/browser/r2/r2/lib/cssfilter.py#L236
, we do this at reddit
2009/6/8 David King <dk...@ketralnis.com>:
>cssText¶
(DOM) The parsable textual representation.
That seems to work on type string?
Is this
cssText¶
(DOM) The parsable textual representation.
Am I right in assuming this is the 'internal' model of the stylesheet
used for processing, as apposed to some other model?
I.e. I should be aiming for this rather than an array or struct of rules?
regards
We only use the cssText to validate URLs (we don't allow off-site
URLs). For everything else, we use the .valid and .wellformed
properties of rules and properties, like <http://code.reddit.com/browser/r2/r2/lib/cssfilter.py#L280
> and <http://code.reddit.com/browser/r2/r2/lib/cssfilter.py#L198>
(esp. the valid_value, which actually checks the "good"ness of a given
value). We iterate over the rules at <http://code.reddit.com/browser/r2/r2/lib/cssfilter.py#L271
> ("for rule in parsed.cssRules")
> We only use the cssText to validate URLs (we don't allow off-site URLs).
Sensible precaution I guess.
For
> everything else, we use the .valid and .wellformed properties of rules and
> properties,
I was expecting 'wellformed' to be a boolean... but it seems not to be?
I tried if wellformed and never found the else clause.
Valid and wellformed I took to be similar to XML well-formedness and
validity... Mmm :-)
like
> <http://code.reddit.com/browser/r2/r2/lib/cssfilter.py#L280> and
> <http://code.reddit.com/browser/r2/r2/lib/cssfilter.py#L198> (esp. the
> valid_value, which actually checks the "good"ness of a given value). We
> iterate over the rules at
> <http://code.reddit.com/browser/r2/r2/lib/cssfilter.py#L271> ("for rule in
> parsed.cssRules")
Thanks for the links.
http://cssutils.googlecode.com/svn/trunk/docs/html/docs/css.html#cssutils.css.CSSRule
Doesn't have any access to the selector, other than via the cssText method which
dumps the entire rule?
Is there a simpler way to get to the selector please?
TIA
Tks Chris.
def checkrules(sheet):
nrules = sheet.cssRules.length
for item in range(0 , nrules):
rule = sheet.cssRules[item] #class cssutils.css.CSSRule
if rule.type == rule.STYLE_RULE:
print rule.selectorText, "{"
for property in rule.style:
print "\t",property.name, " \t:",
print "\t",property.value
if property.valid:
pass
else:
print "Invalid property"
sys.exit(2)
print "}"
print "\t\t-----"
Seems to do what I want, show the rule (and barf at any invalidity :-)
which is what I wanted .... need (with the errors I make in writing CSS).
I've been fighting quirks mode| 'strict' / compliant mode today!
that really is silly!
?Nothing said in the documentation?
> And only in the current alpha releases valid does make more sense. The
> whole validation stuff has been rewritten as you may now defined your
> own properties with valid (or invalid) values.
Interesting. Where is that documented please?