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

0.9.7 is in an very early stage of development. Planned is an implementation of CSS Variables, see the docs in trunk for more info.

current version

Release 0.9.6final 091007. 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 detailsMore info on the pages or downloads referred to on the sitebar.









Hosted by Google Code