2
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
3
from __future__ import with_statement
6
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
7
__docformat__ = 'restructuredtext en'
11
from lxml.etree import tostring as _tostring
13
def tostring(root, strip_comments=False, pretty_print=False):
15
Serialize processed XHTML.
17
root.set('xmlns', 'http://www.w3.org/1999/xhtml')
18
root.set('{http://www.w3.org/1999/xhtml}xlink', 'http://www.w3.org/1999/xlink')
20
if hasattr(x.tag, 'rpartition') and x.tag.rpartition('}')[-1].lower() == 'svg':
21
x.set('xmlns', 'http://www.w3.org/2000/svg')
23
ans = _tostring(root, encoding='utf-8', pretty_print=pretty_print)
25
ans = re.compile(r'<!--.*?-->', re.DOTALL).sub('', ans)
26
ans = '<?xml version="1.0" encoding="utf-8" ?>\n'+ans