Fix merge conflict.

This commit is contained in:
Christopher Ramírez 2014-03-06 00:02:30 -06:00
commit f3e5923737
4 changed files with 66 additions and 18 deletions

View file

@ -38,7 +38,6 @@ import re
import sys
import zipfile
import io
from copy import deepcopy
from xml.dom.minidom import parseString
from jinja2 import Environment, Undefined
@ -252,7 +251,7 @@ class Render(object):
keep_field = field
field_reference = field.getAttribute('text:description')
if re.findall(r'\|markdown', field_content):
# a markdown should take the whole paragraph
field_reference = 'text:p'
@ -295,10 +294,10 @@ class Render(object):
"""
auto_styles = self.content.getElementsByTagName('office:automatic-styles')[0]
if not auto_styles.hasChildNodes():
return None
for style_node in auto_styles.childNodes:
if style_node.hasAttribute('style:name') and \
(style_node.getAttribute('style:name') == style_name):
@ -319,7 +318,7 @@ class Render(object):
style_node.setAttribute('style:name', style_name)
style_node.setAttribute('style:family', 'text')
style_node.setAttribute('style:parent-style-name', 'Standard')
if attributes:
for k, v in attributes.iteritems():
style_node.setAttribute('style:%s' % k, v)
@ -337,6 +336,10 @@ class Render(object):
"""
Convert a markdown text into a ODT formated text
"""
if not isinstance(markdown_text, basestring):
return ''
from xml.dom import Node
from markdown_map import transform_map
@ -345,7 +348,7 @@ class Render(object):
except ImportError:
raise SecretaryError('Could not import markdown2 library. Install it using "pip install markdown2"')
styles_cache = {} # cache styles searching
styles_cache = {} # cache styles searching
html_text = markdown(markdown_text)
xml_object = parseString('<html>%s</html>' % html_text)
@ -394,12 +397,20 @@ class Render(object):
html_node.parentNode.replaceChild(odt_node, html_node)
def node_to_string(node):
result = node.toxml()
result = ''.join(c.toxml() for c in xml_object.getElementsByTagName('html')[0].childNodes)
# A double linebreak should be replacece with an empty paragraph
result = result.replace('\n\n', '<text:p text:style-name="Standard"/>')
return result
# linebreaks in preformated nodes should be converted to <text:line-break/>
if (node.__class__.__name__ != 'Text') and \
(node.getAttribute('text:style-name') == 'Preformatted_20_Text'):
result = result.replace('\n', '<text:line-break/>')
# All double linebreak should be replaced with an empty paragraph
return result.replace('\n\n', '<text:p text:style-name="Standard"/>')
return ''.join(node_as_str for node_as_str in map(node_to_string,
xml_object.getElementsByTagName('html')[0].childNodes))
def render_template(template, **kwargs):
"""