Implement href for links and fix issues with preformated text in markdown filter.
This commit is contained in:
parent
99be02ad63
commit
a0c9478e72
2 changed files with 19 additions and 10 deletions
|
|
@ -51,7 +51,8 @@ transform_map = {
|
||||||
'a': {
|
'a': {
|
||||||
'replace_with': 'text:a',
|
'replace_with': 'text:a',
|
||||||
'attributes': {
|
'attributes': {
|
||||||
'xlink:type': 'simple'
|
'xlink:type': 'simple',
|
||||||
|
'xlink:href': ''
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
26
secretary.py
26
secretary.py
|
|
@ -232,7 +232,7 @@ class Render(object):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
field_description = field.getAttribute('text:description')
|
field_description = field.getAttribute('text:description')
|
||||||
|
|
||||||
if re.findall(r'\|markdown', field_content):
|
if re.findall(r'\|markdown', field_content):
|
||||||
# a markdown should take the whole paragraph
|
# a markdown should take the whole paragraph
|
||||||
field_description = 'text:p'
|
field_description = 'text:p'
|
||||||
|
|
@ -259,10 +259,10 @@ class Render(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
auto_styles = self.content.getElementsByTagName('office:automatic-styles')[0]
|
auto_styles = self.content.getElementsByTagName('office:automatic-styles')[0]
|
||||||
|
|
||||||
if not auto_styles.hasChildNodes():
|
if not auto_styles.hasChildNodes():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for style_node in auto_styles.childNodes:
|
for style_node in auto_styles.childNodes:
|
||||||
if style_node.hasAttribute('style:name') and \
|
if style_node.hasAttribute('style:name') and \
|
||||||
(style_node.getAttribute('style:name') == style_name):
|
(style_node.getAttribute('style:name') == style_name):
|
||||||
|
|
@ -283,7 +283,7 @@ class Render(object):
|
||||||
style_node.setAttribute('style:name', style_name)
|
style_node.setAttribute('style:name', style_name)
|
||||||
style_node.setAttribute('style:family', 'text')
|
style_node.setAttribute('style:family', 'text')
|
||||||
style_node.setAttribute('style:parent-style-name', 'Standard')
|
style_node.setAttribute('style:parent-style-name', 'Standard')
|
||||||
|
|
||||||
if attributes:
|
if attributes:
|
||||||
for k, v in attributes.iteritems():
|
for k, v in attributes.iteritems():
|
||||||
style_node.setAttribute('style:%s' % k, v)
|
style_node.setAttribute('style:%s' % k, v)
|
||||||
|
|
@ -309,7 +309,7 @@ class Render(object):
|
||||||
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"')
|
||||||
|
|
||||||
styles_cache = {} # cache styles searching
|
styles_cache = {} # cache styles searching
|
||||||
html_text = markdown(markdown_text)
|
html_text = markdown(markdown_text)
|
||||||
xml_object = parseString('<html>%s</html>' % html_text)
|
xml_object = parseString('<html>%s</html>' % html_text)
|
||||||
|
|
||||||
|
|
@ -358,12 +358,20 @@ class Render(object):
|
||||||
|
|
||||||
html_node.parentNode.replaceChild(odt_node, html_node)
|
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)
|
# linebreaks in preformated nodes should be converted to <text:line-break/>
|
||||||
# A double linebreak should be replacece with an empty paragraph
|
if (node.__class__.__name__ != 'Text') and \
|
||||||
result = result.replace('\n\n', '<text:p text:style-name="Standard"/>')
|
(node.getAttribute('text:style-name') == 'Preformatted_20_Text'):
|
||||||
return result
|
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):
|
def render_template(template, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue