def _transformSLVToHTML(self, string, editor='kupu', encoding=None): """transform Silva XML to HTML""" transformer = EditorTransformer(editor=editor) # we need to know what browser we are dealing with in order to know # what html to produce, unfortunately Mozilla uses different tags in # some cases (b instead of strong, i instead of em) browser = 'Mozilla' if self.REQUEST['HTTP_USER_AGENT'].find('MSIE') > -1: browser = 'IE' ctx = Context(f=StringIO(), last_version=1, url=self.aq_parent.absolute_url(), browser=browser, model=self.aq_parent) ctx.f.write(string) htmlnode = transformer.to_target(sourceobj=ctx.f.getvalue(), context=ctx) if encoding is not None: ret = htmlnode.asBytes(encoding=encoding) ret = ret.replace('\xa0', ' ') else: ret = unicode(htmlnode.asBytes('utf8'),'utf8') ret = ret.replace(u'\xa0', u' ') return ret
def _transformSLVToHTML(self, string, editor='kupu', encoding=None): """transform Silva XML to HTML""" transformer = EditorTransformer(editor=editor) # we need to know what browser we are dealing with in order to know # what html to produce, unfortunately Mozilla uses different tags in # some cases (b instead of strong, i instead of em) browser = 'Mozilla' if self.REQUEST['HTTP_USER_AGENT'].find('MSIE') > -1: browser = 'IE' ctx = Context(f=StringIO(), last_version=1, url=self.aq_parent.absolute_url(), browser=browser, model=self.aq_parent) ctx.f.write(string) htmlnode = transformer.to_target(sourceobj=ctx.f.getvalue(), context=ctx) if encoding is not None: ret = htmlnode.asBytes(encoding=encoding) ret = ret.replace('\xa0', ' ') else: ret = unicode(htmlnode.asBytes('utf8'), 'utf8') ret = ret.replace(u'\xa0', u' ') return ret
def get_document_xml_as(self, format='kupu', request=None): """Render the Document XML on a different format. """ transformer = EditorTransformer(editor=format) context = Context(self, request) rendered_document = transformer.to_target( sourceobj=self.get_document_xml(), context=context) result = unicode(rendered_document.asBytes('utf8'), 'utf8') result = result.replace(u'\xa0', u' ') return result