replace key attributes for style_attributes in transform_map.

This commit is contained in:
Christopher Ramírez 2013-09-12 17:28:00 -06:00
parent aab74d3ef2
commit 16041cb9c8
2 changed files with 18 additions and 14 deletions

View file

@ -3,13 +3,13 @@
# Transform map used by the markdown filter. transform_map have # Transform map used by the markdown filter. transform_map have
# instructions of how to transform a HTML style tag into a ODT document # 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 # styled tag. Some ODT tags may need extra attributes; these are defined
# as a dict in the 'attributes' key. Also, some tags may need to create # as a dict in the 'style_attributes' key. Also, some tags may need to create
# new styles in the document. # new styles in the document.
common_styles = { common_styles = {
'italic': { 'italic': {
'replace_with': 'text:span', 'replace_with': 'text:span',
'attributes': { 'style_attributes': {
'style-name': 'markdown_italic' 'style-name': 'markdown_italic'
}, },
@ -25,7 +25,7 @@ common_styles = {
'strong': { 'strong': {
'replace_with': 'text:span', 'replace_with': 'text:span',
'attributes': { 'style_attributes': {
'style-name': 'markdown_bold' 'style-name': 'markdown_bold'
}, },
@ -41,13 +41,17 @@ common_styles = {
'p': { 'p': {
'replace_with': 'text:p', 'replace_with': 'text:p',
'attributes': { 'style_attributes': {
'style-name': 'Standard' 'style-name': 'Standard'
} }
} }
} }
transform_map = { transform_map = {
'a': {
'replace_with': 'text:a',
},
'p': common_styles['p'], 'p': common_styles['p'],
'strong': common_styles['strong'], 'strong': common_styles['strong'],
'em': common_styles['italic'], 'em': common_styles['italic'],
@ -57,42 +61,42 @@ transform_map = {
# Heading Styles (Use styles defined in the document) # Heading Styles (Use styles defined in the document)
'h1': { 'h1': {
'replace_with': 'text:p', 'replace_with': 'text:p',
'attributes': { 'style_attributes': {
'style-name': 'Heading_20_1' 'style-name': 'Heading_20_1'
} }
}, },
'h2': { 'h2': {
'replace_with': 'text:p', 'replace_with': 'text:p',
'attributes': { 'style_attributes': {
'style-name': 'Heading_20_2' 'style-name': 'Heading_20_2'
} }
}, },
'h3': { 'h3': {
'replace_with': 'text:p', 'replace_with': 'text:p',
'attributes': { 'style_attributes': {
'style-name': 'Heading_20_3' 'style-name': 'Heading_20_3'
} }
}, },
'h4': { 'h4': {
'replace_with': 'text:p', 'replace_with': 'text:p',
'attributes': { 'style_attributes': {
'style-name': 'Heading_20_4' 'style-name': 'Heading_20_4'
} }
}, },
'pre': { 'pre': {
'replace_with': 'text:p', 'replace_with': 'text:p',
'attributes': { 'style_attributes': {
'style-name': 'Preformatted_20_Text' 'style-name': 'Preformatted_20_Text'
} }
}, },
'code': { 'code': {
'replace_with': 'text:span', 'replace_with': 'text:span',
'attributes': { 'style_attributes': {
'style-name': 'Preformatted_20_Text' 'style-name': 'Preformatted_20_Text'
} }
}, },

View file

@ -327,9 +327,9 @@ class Render(object):
for child_node in html_node.childNodes: for child_node in html_node.childNodes:
odt_node.appendChild(child_node.cloneNode(True)) odt_node.appendChild(child_node.cloneNode(True))
# Add attributes defined in transform_map # Add style attributes defined in transform_map
if 'attributes' in transform_map[tag]: if 'style_attributes' in transform_map[tag]:
for k, v in transform_map[tag]['attributes'].iteritems(): for k, v in transform_map[tag]['style_attributes'].iteritems():
odt_node.setAttribute('text:%s' % k, v) odt_node.setAttribute('text:%s' % k, v)
# Does the node need to create an style? # Does the node need to create an style?