File: styledeclaration.py

package info (click to toggle)
cssutils 2.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,312 kB
  • sloc: python: 23,625; javascript: 803; sh: 62; makefile: 8
file content (53 lines) | stat: -rw-r--r-- 1,341 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import cssutils


def show(style):
    print("style.length ==", style.length)
    print("style.item(0) ==", style.item(0))
    print("style.item(1) ==", style.item(1))
    print("style.getProperties('color', all=True) == [")
    for x in style.getProperties('color', all=True):
        print("\t", x.cssText)
    print("\t]")
    print("style.getPropertyValue('color') ==", style.getPropertyValue('color'), '\n')


styledeclaration = r'''
x:1;
color: yellow;
color: red;
c\olor: green !important;
c\olor: blue;
FONT-FAMILY: serif;
'''
print("\nGiven styledeclaration:")
print(styledeclaration)
print("------------")

print("setting cssText")
style = cssutils.css.CSSStyleDeclaration(cssText=styledeclaration)
show(style)

print("------------")

# overwrite in any case
print("style.setProperty('color', 'yellow','!important')")
style.setProperty('color', 'yellow', '!important')
show(style)

# overwrite in any case, even !important
print("style.setProperty('color', 'red')")
style.setProperty('color', 'red')
show(style)

print("------------")

# overwrite in any case, even !important
print("style.setProperty('color', 'green', '!important')")
style.setProperty('color', 'green', '!important')
show(style)

# overwrite in any case, even !important
print("style.setProperty('color', 'blue')")
style.setProperty('color', 'blue')
show(style)