def set_document_xml_from(self, data, format='kupu', request=None): """Set the document xml of the version from the given data in the given format. """ transformer = EditorTransformer(editor=format) context = Context(self, request) document = transformer.to_source(targetobj=data, context=context)[0] title = document.find('title')[0].extract_text() content = document.find('doc')[0].asBytes(encoding="UTF8") self.content.manage_edit(content) self.set_title(title) notify(lifecycleevent.ObjectModifiedEvent(self))
def _transformHTMLToSLV(self, string, editor='kupu', encoding=None): """transform (messy structure-wise) HTML to Silva XML""" 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(url=self.aq_parent.absolute_url(), browser=browser, model=self.aq_parent, request=self.REQUEST) silvanode = transformer.to_source(targetobj=string, context=ctx)[0] title = silvanode.find('title')[0].extract_text() # unicode docnode = silvanode.find('doc')[0] content = docnode.asBytes(encoding="UTF8") # UTF-8 return title, content