• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H24-May-2021-5650

cssutils/H24-May-2021-40,48332,453

cssutils.egg-info/H03-May-2022-163124

docs/H24-May-2021-2,0341,557

encutils/H24-May-2021-688515

examples/H24-May-2021-1,014766

sheets/H03-May-2022-8,2657,735

tools/H24-May-2021-1,5341,144

.coveragercH A D24-May-202199 86

.editorconfigH A D24-May-2021195 1612

.flake8H A D24-May-2021171 129

.pre-commit-config.yamlH A D24-May-2021175 119

.readthedocs.ymlH A D24-May-202179 76

CHANGES.rstH A D24-May-2021118.6 KiB1,8551,221

COPYINGH A D24-May-202135 KiB675553

COPYING.LESSERH A D24-May-20217.6 KiB166128

PKG-INFOH A D24-May-20217.4 KiB163124

README.rstH A D24-May-20216.4 KiB13599

conftest.pyH A D24-May-2021489 2618

mypy.iniH A D24-May-202137 32

pyproject.tomlH A D24-May-2021369 2114

pytest.iniH A D24-May-2021198 87

setup.cfgH A D24-May-20211.7 KiB7163

setup.pyH A D24-May-202169 53

tox.iniH A D24-May-2021723 4136

README.rst

1.. image:: https://img.shields.io/pypi/v/cssutils.svg
2   :target: `PyPI link`_
3
4.. image:: https://img.shields.io/pypi/pyversions/cssutils.svg
5   :target: `PyPI link`_
6
7.. _PyPI link: https://pypi.org/project/cssutils
8
9.. image:: https://github.com/jaraco/cssutils/workflows/tests/badge.svg
10   :target: https://github.com/jaraco/cssutils/actions?query=workflow%3A%22tests%22
11   :alt: tests
12
13.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
14   :target: https://github.com/psf/black
15   :alt: Code style: Black
16
17.. image:: https://readthedocs.org/projects/cssutils/badge/?version=latest
18   :target: https://cssutils.readthedocs.io/en/latest/?badge=latest
19
20.. image:: https://img.shields.io/badge/skeleton-2021-informational
21   :target: https://blog.jaraco.com/skeleton
22
23
24Overview
25========
26A Python package to parse and build CSS Cascading Style Sheets. DOM only, not any rendering facilities!
27
28Based upon and partly implementing the following specifications :
29
30`CSS 2.1rev1 <http://www.w3.org/TR/CSS2/>`__
31    General CSS rules and properties are defined here
32`CSS3 Module: Syntax <http://www.w3.org/TR/css3-syntax/>`__
33    Used in parts since cssutils 0.9.4. cssutils tries to use the features from CSS 2.1 and CSS 3 with preference to CSS3 but as this is not final yet some parts are from CSS 2.1
34`CSS Fonts Module Level 3 <http://www.w3.org/TR/css3-fonts/>`__
35    Added changes and additional stuff (since cssutils v0.9.6)
36`MediaQueries <http://www.w3.org/TR/css3-mediaqueries/>`__
37    MediaQueries are part of ``stylesheets.MediaList`` since v0.9.4, used in @import and @media rules.
38`Namespaces <http://dev.w3.org/csswg/css3-namespace/>`__
39    Added in v0.9.1, updated to definition in CSSOM in v0.9.4, updated in 0.9.5 for dev version
40`CSS3 Module: Pages Media <http://www.w3.org/TR/css3-page/>`__
41    Most properties of this spec are implemented including MarginRules
42`Selectors <http://www.w3.org/TR/css3-selectors/>`__
43    The selector syntax defined here (and not in CSS 2.1) should be parsable with cssutils (*should* mind though ;) )
44`CSS Backgrounds and Borders Module Level 3 <http://www.w3.org/TR/css3-background/>`__, `CSS3 Basic User Interface Module <http://www.w3.org/TR/css3-ui/#resize>`__, `CSS Text Level 3 <http://www.w3.org/TR/css3-text/>`__
45    Some validation for properties included, mainly  `cursor`, `outline`, `resize`, `box-shadow`, `text-shadow`
46`Variables <http://disruptive-innovations.com/zoo/cssvariables/>`__ / `CSS Custom Properties <http://dev.w3.org/csswg/css-variables/>`__
47    Experimental specification of CSS Variables which cssutils implements partly. The vars defined in the newer CSS Custom Properties spec should in main parts be at least parsable with cssutils.
48
49`DOM Level 2 Style CSS <http://www.w3.org/TR/DOM-Level-2-Style/css.html>`__
50    DOM for package css. 0.9.8 removes support for CSSValue and related API, see PropertyValue and Value API for now
51`DOM Level 2 Style Stylesheets <http://www.w3.org/TR/DOM-Level-2-Style/stylesheets.html>`__
52    DOM for package stylesheets
53`CSSOM <http://dev.w3.org/csswg/cssom/>`__
54    A few details (mainly the NamespaceRule DOM) are taken from here. Plan is to move implementation to the stuff defined here which is newer but still no REC so might change anytime...
55
56The cssutils tokenizer is a customized implementation of `CSS3 Module: Syntax (W3C Working Draft 13 August 2003) <http://www.w3.org/TR/css3-syntax/>`_ which itself is based on the CSS 2.1 tokenizer. It tries to be as compliant as possible but uses some (helpful) parts of the CSS 2.1 tokenizer.
57
58I guess cssutils is neither CSS 2.1 nor CSS 3 compliant but tries to at least be able to parse both grammars including some more real world cases (some CSS hacks are actually parsed and serialized). Both official grammars are not final nor bugfree but still feasible. cssutils aim is not to be fully compliant to any CSS specification (the specifications seem to be in a constant flow anyway) but cssutils *should* be able to read and write as many as possible CSS stylesheets "in the wild" while at the same time implement the official APIs which are well documented. Some minor extensions are provided as well.
59
60Please visit http://cthedot.de/cssutils/ or https://bitbucket.org/cthedot/cssutils/ for more details.
61
62There is also a low-traffic `cssutils discussion group <http://groups.google.com/group/cssutils>`_.
63
64
65Compatibility
66=============
67
68cssutils is developed on modern Python versions. Check the package metadata
69for compatibilty.
70
71Beware, cssutils is known to be thread unsafe.
72
73
74Example
75=======
76::
77
78    import cssutils
79
80    css = '''/* a comment with umlaut &auml; */
81         @namespace html "http://www.w3.org/1999/xhtml";
82         @variables { BG: #fff }
83         html|a { color:red; background: var(BG) }'''
84    sheet = cssutils.parseString(css)
85
86    for rule in sheet:
87        if rule.type == rule.STYLE_RULE:
88            # find property
89            for property in rule.style:
90                if property.name == 'color':
91                    property.value = 'green'
92                    property.priority = 'IMPORTANT'
93                    break
94            # or simply:
95            rule.style['margin'] = '01.0eM' # or: ('1em', 'important')
96
97    sheet.encoding = 'ascii'
98    sheet.namespaces['xhtml'] = 'http://www.w3.org/1999/xhtml'
99    sheet.namespaces['atom'] = 'http://www.w3.org/2005/Atom'
100    sheet.add('atom|title {color: #000000 !important}')
101    sheet.add('@import "sheets/import.css";')
102
103    # cssutils.ser.prefs.resolveVariables == True since 0.9.7b2
104    print sheet.cssText
105
106results in::
107
108	@charset "ascii";
109	@import "sheets/import.css";
110	/* a comment with umlaut \E4  */
111	@namespace xhtml "http://www.w3.org/1999/xhtml";
112	@namespace atom "http://www.w3.org/2005/Atom";
113	xhtml|a {
114	    color: green !important;
115	    background: #fff;
116	    margin: 1em
117	    }
118	atom|title {
119	    color: #000 !important
120	    }
121
122
123Kind Request
124============
125
126cssutils is far from being perfect or even complete. If you find any bugs (especially specification violations) or have problems or suggestions please put them in the `Issue Tracker <https://github.com/jaraco/cssutils/issues>`_.
127
128
129Thanks
130======
131
132Special thanks to Christof Höke for seminal creation of the library.
133
134Thanks to Simon Sapin, Jason R. Coombs, and Walter Doerwald for patches, help and discussion. Thanks to Kevin D. Smith for the value validating module. Thanks also to Cory Dodt, Tim Gerla, James Dobson and Amit Moscovich for helpful suggestions and code patches. Thanks to Fredrik Hedman for help on port of encutils to Python 3.
135