|
7 | 7 | :target: https://github.com/jaraco/cssutils/actions?query=workflow%3A%22tests%22 |
8 | 8 | :alt: tests |
9 | 9 |
|
10 | | -.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json |
| 10 | +.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json |
11 | 11 | :target: https://github.com/astral-sh/ruff |
12 | 12 | :alt: Ruff |
13 | 13 |
|
14 | 14 | .. image:: https://readthedocs.org/projects/cssutils/badge/?version=latest |
15 | 15 | :target: https://cssutils.readthedocs.io/en/latest/?badge=latest |
16 | 16 |
|
17 | | -.. image:: https://img.shields.io/badge/skeleton-2025-informational |
| 17 | +.. image:: https://img.shields.io/badge/skeleton-2026-informational |
18 | 18 | :target: https://blog.jaraco.com/skeleton |
19 | 19 |
|
20 | 20 | .. image:: https://tidelift.com/badges/package/pypi/cssutils |
@@ -69,35 +69,36 @@ Beware, cssutils is known to be thread unsafe. |
69 | 69 |
|
70 | 70 | Example |
71 | 71 | ======= |
72 | | -```python |
73 | | -import cssutils |
74 | | -
|
75 | | -css = '''/* a comment with umlaut ä */ |
76 | | - @namespace html "http://www.w3.org/1999/xhtml"; |
77 | | - @variables { BG: #fff } |
78 | | - html|a { color:red; background: var(BG) }''' |
79 | | -sheet = cssutils.parseString(css) |
80 | | -
|
81 | | -for rule in sheet: |
82 | | - if rule.type == rule.STYLE_RULE: |
83 | | - # find property |
84 | | - for property in rule.style: |
85 | | - if property.name == 'color': |
86 | | - property.value = 'green' |
87 | | - property.priority = 'IMPORTANT' |
88 | | - break |
89 | | - # or simply: |
90 | | - rule.style['margin'] = '01.0eM' # or: ('1em', 'important') |
91 | | -
|
92 | | -sheet.encoding = 'ascii' |
93 | | -sheet.namespaces['xhtml'] = 'http://www.w3.org/1999/xhtml' |
94 | | -sheet.namespaces['atom'] = 'http://www.w3.org/2005/Atom' |
95 | | -sheet.add('atom|title {color: #000000 !important}') |
96 | | -sheet.add('@import "sheets/import.css";') |
97 | | -
|
98 | | -# cssutils.ser.prefs.resolveVariables == True since 0.9.7b2 |
99 | | -print sheet.cssText |
100 | | -``` |
| 72 | +:: |
| 73 | + |
| 74 | + import cssutils |
| 75 | + |
| 76 | + css = '''/* a comment with umlaut ä */ |
| 77 | + @namespace html "http://www.w3.org/1999/xhtml"; |
| 78 | + @variables { BG: #fff } |
| 79 | + html|a { color:red; background: var(BG) }''' |
| 80 | + sheet = cssutils.parseString(css) |
| 81 | + |
| 82 | + for rule in sheet: |
| 83 | + if rule.type == rule.STYLE_RULE: |
| 84 | + # find property |
| 85 | + for property in rule.style: |
| 86 | + if property.name == 'color': |
| 87 | + property.value = 'green' |
| 88 | + property.priority = 'IMPORTANT' |
| 89 | + break |
| 90 | + # or simply: |
| 91 | + rule.style['margin'] = '01.0eM' # or: ('1em', 'important') |
| 92 | + |
| 93 | + sheet.encoding = 'ascii' |
| 94 | + sheet.namespaces['xhtml'] = 'http://www.w3.org/1999/xhtml' |
| 95 | + sheet.namespaces['atom'] = 'http://www.w3.org/2005/Atom' |
| 96 | + sheet.add('atom|title {color: #000000 !important}') |
| 97 | + sheet.add('@import "sheets/import.css";') |
| 98 | + |
| 99 | + # cssutils.ser.prefs.resolveVariables == True since 0.9.7b2 |
| 100 | + print sheet.cssText |
| 101 | + |
101 | 102 | results in:: |
102 | 103 |
|
103 | 104 | @charset "ascii"; |
|
0 commit comments