My favorites | Sign in
Project Logo
             
People details
Project owners:
  cthedot
Project committers:
doerwalter

cssutils

A Python package to parse and build CSS Cascading Style Sheets.

Actually querying a parsed stylesheet on a given document or element is planned for probably 0.9.7, for now see the example examples/style.py.

example

# -*- coding: utf-8 -*-
import cssutils

css = u'''/* a comment with umlaut รค */ 
     @namespace html "http://www.w3.org/1999/xhtml";
     html|a { color:red; }'''
sheet = cssutils.parseString(css)

for rule in sheet:
    if rule.type == rule.STYLE_RULE:
        for property in rule.style:
            property.value = 'green' 
            property.priority = 'IMPORTANT'
        rule.style['margin'] = '01.0eM' # or: ('1em', 'important')

sheet.encoding = 'ascii'
sheet.namespaces['xhtml'] = 'http://www.w3.org/1999/xhtml'
sheet.namespaces['atom'] = 'http://www.w3.org/2005/Atom'
sheet.add('atom|title {color: #000000 !important}')
sheet.add('@import "sheets/import.css";')

results in

@charset "ascii";
@import "sheets/import.css";
/* a comment with umlaut \E4  */
@namespace xhtml "http://www.w3.org/1999/xhtml";
@namespace atom "http://www.w3.org/2005/Atom";
xhtml|a {
    color: green !important;
    margin: 1em
    }
atom|title {
    color: #000 !important
    }

development version (currently alpha)

Release 0.9.6b1 090609. A few non-backwards compatible changes have been made, please see the online docs help to migrate to 0.9.6. See the docs for full details but the main points here:

More info on the pages or downloads referred to on the sitebar.

deprecated version

Release 0.9.5.1 080811. See the README and CHANGELOG for details. Please see MIGRATE for help to migrate to 0.9.5 from lower versions.









Hosted by Google Code