forked from christopher-ramirez/secretary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdown_map.py
131 lines (112 loc) · 2.91 KB
/
markdown_map.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/python
from random import randint
# Transform map used by the markdown filter. transform_map have
# instructions of how to transform a HTML style tag into a ODT document
# styled tag. Some ODT tags may need extra attributes; these are defined
# as a dict in the 'style_attributes' key. Also, some tags may need to create
# new styles in the document.
common_styles = {
'italic': {
'replace_with': 'text:span',
'style_attributes': {
'style-name': 'markdown_italic'
},
'style': {
'name': 'markdown_italic',
'properties': {
'fo:font-style': 'italic',
'style:font-style-asian': 'italic',
'style:font-style-complex': 'italic'
}
}
},
'strong': {
'replace_with': 'text:span',
'style_attributes': {
'style-name': 'markdown_bold'
},
'style': {
'name': 'markdown_bold',
'properties': {
'fo:font-weight': 'bold',
'style:font-weight-asian': 'bold',
'style:font-weight-complex': 'bold'
}
}
},
'p': {
'replace_with': 'text:p',
'style_attributes': {
'style-name': 'Standard'
}
}
}
transform_map = {
'a': {
'replace_with': 'text:a',
'attributes': {
'xlink:type': 'simple',
'xlink:href': ''
}
},
'p': common_styles['p'],
'strong': common_styles['strong'],
'em': common_styles['italic'],
'b': common_styles['strong'],
'i': common_styles['italic'],
# Heading Styles (Use styles defined in the document)
'h1': {
'replace_with': 'text:p',
'style_attributes': {
'style-name': 'Heading_20_1'
}
},
'h2': {
'replace_with': 'text:p',
'style_attributes': {
'style-name': 'Heading_20_2'
}
},
'h3': {
'replace_with': 'text:p',
'style_attributes': {
'style-name': 'Heading_20_3'
}
},
'h4': {
'replace_with': 'text:p',
'style_attributes': {
'style-name': 'Heading_20_4'
}
},
'pre': {
'replace_with': 'text:p',
'style_attributes': {
'style-name': 'Preformatted_20_Text'
}
},
'code': {
'replace_with': 'text:span',
'style_attributes': {
'style-name': 'Preformatted_20_Text'
}
},
'ul': {
'replace_with': 'text:list',
'attributes': {
'xml:id': 'list' + str(randint(100000000000000000,900000000000000000))
}
},
'ol': {
'replace_with': 'text:list',
'attributes': {
'xml:id': 'list' + str(randint(100000000000000000,900000000000000000))
}
},
'li': {
'replace_with': 'text:list-item'
},
'br': {
'replace_with': 'text:line-break'
},
}