2013-09-12 13:23:24 -06:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
|
2013-10-24 12:09:15 -06:00
|
|
|
from random import randint
|
|
|
|
|
|
2013-09-12 13:23:24 -06:00
|
|
|
# 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
|
2013-09-12 17:28:00 -06:00
|
|
|
# as a dict in the 'style_attributes' key. Also, some tags may need to create
|
2013-09-12 13:23:24 -06:00
|
|
|
# new styles in the document.
|
|
|
|
|
|
2013-09-12 15:50:17 -06:00
|
|
|
common_styles = {
|
|
|
|
|
'italic': {
|
|
|
|
|
'replace_with': 'text:span',
|
2013-09-12 17:28:00 -06:00
|
|
|
'style_attributes': {
|
2013-09-12 15:50:17 -06:00
|
|
|
'style-name': 'markdown_italic'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'style': {
|
|
|
|
|
'name': 'markdown_italic',
|
|
|
|
|
'properties': {
|
|
|
|
|
'fo:font-style': 'italic',
|
|
|
|
|
'style:font-style-asian': 'italic',
|
|
|
|
|
'style:font-style-complex': 'italic'
|
|
|
|
|
}
|
2013-09-12 13:23:24 -06:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'strong': {
|
|
|
|
|
'replace_with': 'text:span',
|
2013-09-12 17:28:00 -06:00
|
|
|
'style_attributes': {
|
2013-09-12 13:23:24 -06:00
|
|
|
'style-name': 'markdown_bold'
|
|
|
|
|
},
|
|
|
|
|
|
2013-09-12 13:59:47 -06:00
|
|
|
'style': {
|
2013-09-12 13:23:24 -06:00
|
|
|
'name': 'markdown_bold',
|
|
|
|
|
'properties': {
|
|
|
|
|
'fo:font-weight': 'bold',
|
|
|
|
|
'style:font-weight-asian': 'bold',
|
|
|
|
|
'style:font-weight-complex': 'bold'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2013-10-24 12:09:15 -06:00
|
|
|
'p': {
|
2013-09-12 15:50:17 -06:00
|
|
|
'replace_with': 'text:p',
|
2013-09-12 17:28:00 -06:00
|
|
|
'style_attributes': {
|
2013-09-12 15:50:17 -06:00
|
|
|
'style-name': 'Standard'
|
2013-09-12 13:23:24 -06:00
|
|
|
}
|
2013-09-12 15:50:17 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
transform_map = {
|
2013-09-12 17:28:00 -06:00
|
|
|
'a': {
|
|
|
|
|
'replace_with': 'text:a',
|
2013-09-12 17:30:09 -06:00
|
|
|
'attributes': {
|
2013-10-24 11:09:44 -06:00
|
|
|
'xlink:type': 'simple',
|
|
|
|
|
'xlink:href': ''
|
2013-09-12 17:30:09 -06:00
|
|
|
}
|
2013-09-12 17:28:00 -06:00
|
|
|
},
|
|
|
|
|
|
2013-09-12 15:50:17 -06:00
|
|
|
'p': common_styles['p'],
|
|
|
|
|
'strong': common_styles['strong'],
|
|
|
|
|
'em': common_styles['italic'],
|
|
|
|
|
'b': common_styles['strong'],
|
|
|
|
|
'i': common_styles['italic'],
|
2013-09-12 13:23:24 -06:00
|
|
|
|
|
|
|
|
# Heading Styles (Use styles defined in the document)
|
|
|
|
|
'h1': {
|
|
|
|
|
'replace_with': 'text:p',
|
2013-09-12 17:28:00 -06:00
|
|
|
'style_attributes': {
|
2013-09-12 13:23:24 -06:00
|
|
|
'style-name': 'Heading_20_1'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'h2': {
|
|
|
|
|
'replace_with': 'text:p',
|
2013-09-12 17:28:00 -06:00
|
|
|
'style_attributes': {
|
2013-09-12 13:23:24 -06:00
|
|
|
'style-name': 'Heading_20_2'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'h3': {
|
|
|
|
|
'replace_with': 'text:p',
|
2013-09-12 17:28:00 -06:00
|
|
|
'style_attributes': {
|
2013-09-12 13:23:24 -06:00
|
|
|
'style-name': 'Heading_20_3'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'h4': {
|
|
|
|
|
'replace_with': 'text:p',
|
2013-09-12 17:28:00 -06:00
|
|
|
'style_attributes': {
|
2013-09-12 13:23:24 -06:00
|
|
|
'style-name': 'Heading_20_4'
|
|
|
|
|
}
|
|
|
|
|
},
|
2013-09-12 17:28:00 -06:00
|
|
|
|
2013-09-12 17:23:08 -06:00
|
|
|
'pre': {
|
|
|
|
|
'replace_with': 'text:p',
|
2013-09-12 17:28:00 -06:00
|
|
|
'style_attributes': {
|
2013-09-12 17:23:08 -06:00
|
|
|
'style-name': 'Preformatted_20_Text'
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'code': {
|
|
|
|
|
'replace_with': 'text:span',
|
2013-09-12 17:28:00 -06:00
|
|
|
'style_attributes': {
|
2013-09-12 17:23:08 -06:00
|
|
|
'style-name': 'Preformatted_20_Text'
|
|
|
|
|
}
|
|
|
|
|
},
|
2013-10-24 12:09:15 -06:00
|
|
|
|
|
|
|
|
'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'
|
|
|
|
|
},
|
2013-09-12 13:23:24 -06:00
|
|
|
}
|