forked from jaraco/cssutils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserialize.py
More file actions
67 lines (52 loc) · 1.73 KB
/
serialize.py
File metadata and controls
67 lines (52 loc) · 1.73 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import logging
import cssutils
cssutils.log.setLevel(logging.FATAL)
css = r'''@import "example.css";
a {
color: blue !important;
c\olor: green !important;
c\olor: pink;
color: red;
}'''
sheet = cssutils.parseString(css)
print("\nORIGINAL CSS:")
print(css)
print("------------")
print(repr(cssutils.ser.prefs))
print("\nCSS Serialized")
print(sheet.cssText)
print("\nCSS Serialized with ``keepAllProperties`` = False")
cssutils.ser.prefs.keepAllProperties = False
print(sheet.cssText)
print("\nCSS Serialized with ``defaultPropertyName`` = True")
cssutils.ser.prefs.defaultPropertyName = True
print(sheet.cssText)
print("\nCSS Serialized with ``defaultPropertyName`` = False")
cssutils.ser.prefs.defaultPropertyName = False
print(sheet.cssText)
print('\nBUT: Reading value programmatic uses normalized property')
print(' name and results in actual value only:')
print('\t.getPropertyValue("color") ==', end=' ')
print(sheet.cssRules[1].style.getPropertyValue('color'))
print('\t.getPropertyValue("c\\olor") ==', end=' ')
print(sheet.cssRules[1].style.getPropertyValue(r'c\olor'))
print('\t.getPropertyValue("c\\o\\l\\o\\r") ==', end=' ')
print(sheet.cssRules[1].style.getPropertyValue('c\\o\\l\\o\\r'))
print()
print(
'\nCSS Serialized with indent = 2*" ", importHrefFormat="string", lineNumbers=True'
)
cssutils.ser.prefs.indent = 2 * ' '
# used to set indentation string, default is 4*' '
cssutils.ser.prefs.importHrefFormat = 'string'
# or 'uri', defaults to the format used in parsed stylesheet
cssutils.ser.prefs.lineNumbers = True
print(sheet.cssText)
print('\nCSS Serialized with useMinified()')
cssutils.ser.prefs.useMinified()
print(sheet.cssText)
# OUTPUTS
# 1: @import "example.css";
# 2: body {
# 3: color: red
# 4: }