Skip to content

Commit

Permalink
Merge pull request #54 from Solarmove/patch-1
Browse files Browse the repository at this point in the history
add python syntax in readme
  • Loading branch information
jaraco authored Dec 23, 2024
2 parents b71fc01 + 719cb95 commit 3374239
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,36 +69,35 @@ Beware, cssutils is known to be thread unsafe.

Example
=======
::

import cssutils

css = '''/* a comment with umlaut ä */
@namespace html "http://www.w3.org/1999/xhtml";
@variables { BG: #fff }
html|a { color:red; background: var(BG) }'''
sheet = cssutils.parseString(css)

for rule in sheet:
if rule.type == rule.STYLE_RULE:
# find property
for property in rule.style:
if property.name == 'color':
property.value = 'green'
property.priority = 'IMPORTANT'
break
# or simply:
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";')

# cssutils.ser.prefs.resolveVariables == True since 0.9.7b2
print sheet.cssText

```python
import cssutils
css = '''/* a comment with umlaut ä */
@namespace html "http://www.w3.org/1999/xhtml";
@variables { BG: #fff }
html|a { color:red; background: var(BG) }'''
sheet = cssutils.parseString(css)
for rule in sheet:
if rule.type == rule.STYLE_RULE:
# find property
for property in rule.style:
if property.name == 'color':
property.value = 'green'
property.priority = 'IMPORTANT'
break
# or simply:
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";')
# cssutils.ser.prefs.resolveVariables == True since 0.9.7b2
print sheet.cssText
```
results in::

@charset "ascii";
Expand Down

0 comments on commit 3374239

Please sign in to comment.