Commit e473c85e authored by Nicolas Delaby's avatar Nicolas Delaby

Rely on include_meta_content_type parameter of lxml.html.tostring API to setup correct

meta tag.
Previous implementation was not adding the content-type meta tag in all cases.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@45321 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5fe84f1c
......@@ -32,17 +32,8 @@ class HTMLToOdt:
def convert(self, orig, data, cache=None, filename=None, context=None, **kwargs):
# Try to recover broken HTML documents, specially regarding encoding used
html_node = etree.XML(orig, parser=html_parser)
html_tree = html_node.getroottree()
head = html_tree.find('head')
if head is None:
# This part of code is supposed to be useless
# lxml.html.tostring function with include_meta_content_type
# parameter to True, should do the same things. But it does not.
head = Element('head')
html_node.insert(0, head)
SubElement(head, 'meta', **{'http-equiv': 'Content-Type',
'content': 'text/html; charset=utf-8'})
orig = html.tostring(html_node, encoding='utf-8', method='xml')
orig = html.tostring(html_node, encoding='utf-8', method='xml',
include_meta_content_type=True)
# workaround a Bug in LibreOffice HTML import filter.
# https://bugs.freedesktop.org/show_bug.cgi?id=36080
......
......@@ -194,7 +194,8 @@ class OOOdCommandTransform(commandtransform):
parent_node.append(style_node)
style_node.attrib.update({'type': 'text/css'})
parent_node.remove(css_link_tag)
xml_output = html.tostring(xml_doc, encoding='utf-8', method='xml')
xml_output = html.tostring(xml_doc, encoding='utf-8', method='xml',
include_meta_content_type=True)
xml_output = xml_output.replace('<title/>', '<title></title>')
return xml_output
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment