HTML > ODT starts to work

This commit is contained in:
Christopher Ramírez 2013-09-05 09:51:34 -06:00
parent 99cb204ca0
commit 9d94cda03f

View file

@ -254,8 +254,10 @@ def markdown_filter(markdown_text):
Convert a markdown text into a ODT formated text Convert a markdown text into a ODT formated text
""" """
from copy import deepcopy, copy
from xml.dom import Node
try: try:
from copy import deepcopy
from markdown2 import markdown from markdown2 import markdown
except ImportError: except ImportError:
raise SecretaryError('Could not import markdown2 library. Install it using "pip install markdown2"') raise SecretaryError('Could not import markdown2 library. Install it using "pip install markdown2"')
@ -272,6 +274,11 @@ def markdown_filter(markdown_text):
'strong': { 'strong': {
'replace_with': 'text:span', 'replace_with': 'text:span',
'attributes': {} 'attributes': {}
},
'i': {
'replace_with': 'text:span',
'attributes': {}
} }
} }
@ -288,16 +295,16 @@ def markdown_filter(markdown_text):
# Transfer child nodes # Transfer child nodes
if html_node.hasChildNodes(): if html_node.hasChildNodes():
for child_node in html_node.childNodes: for child_node in html_node.childNodes:
odt_node.appendChild(deepcopy(child_node))
if child_node.nodeType == Node.ELEMENT_NODE:
odt_node.appendChild(child_node.cloneNode(True))
else:
odt_node.appendChild(deepcopy(child_node))
html_node.parentNode.replaceChild(odt_node, html_node) html_node.parentNode.replaceChild(odt_node, html_node)
return xml_object.toxml() return xml_object.firstChild.toxml()
def render_template(template, **kwargs): def render_template(template, **kwargs):