def _loadStringFromFile(self, html): # MSHTML control requires a <head> and <title> element title = getNoneString(extractTitle(html)) if not title or html.find(u"<html") == -1: #$NON-NLS-1$ # case where only the body content is given or the content did not have non-empty <head> and <title> elems. # try and create wrapper around the body. Eg: <html><head><title>ZoundryDocument</title></head><body> CONTENT </body> </html> html = wrapHtmlBody(html, u"ZoundryDocument") #$NON-NLS-1$ # note: \r\n must be replace with \n. Otherwise, in <pre> blocks, the \r' will show up as an extra line. html = html.replace(u"\r\n", u"\n") #$NON-NLS-1$ #$NON-NLS-2$ # For the test-harness to work, hard code temp dir tmpDir = u"c:/temp" #$NON-NLS-1$ if getApplicationModel(): userProfile = getApplicationModel().getUserProfile() tmpDir = userProfile.getTempDirectory() d = str(time.time()) fname = os.path.join(tmpDir, u"_z_raven_mshtml_%s_tmp.xhtml" % d) #$NON-NLS-1$ tmpFile = codecs.open(fname, u"w") #$NON-NLS-1$ try: # write the utf-8 byte order marker for wintel platforms. tmpFile.write(codecs.BOM_UTF8) tmpFile.write(convertToUtf8(html)) tmpFile.close() self._loadFile(fname) finally: tmpFile.close()
def _prepareForLoading(self, xhtmlString): u"""Prepares the raw xhtml string for loading into zDom.""" #$NON-NLS-1$ xhtmlString = xhtmlString.lstrip() if xhtmlString.startswith(u"<!DOCTYPE"): #$NON-NLS-1$ xhtmlString = xhtmlString[xhtmlString.find(u">") + 1:] #$NON-NLS-1$ xhtmlString = xhtmlString.replace(u' ', u' ') #$NON-NLS-1$ #$NON-NLS-2$ (bOk, xhtmlString) = self._cleanupMsOffice(xhtmlString) #@UnusedVariable # if the string content does not have a <body/> then convert to xhtml and wrap it # with <html><body/></html> if not xhtmlutil.hasBody(xhtmlString): if not xhtmlutil.hasXhtmlMarkup(xhtmlString): self.messages.append( u"Converting plain text to xhtml markup.") #$NON-NLS-1$ # convert plain text to xhtml transformer = ZTextToXhtmlTransformer() xhtmlString = transformer.transform(xhtmlString) xhtmlString = xhtmlutil.wrapHtmlBody(xhtmlString) self.messages.append( u"Adding <html><body></body></html> wrapper.") #$NON-NLS-1$ return xhtmlString
def _loadStringFromFile(self, html): # MSHTML control requires a <head> and <title> element title = getNoneString( extractTitle(html) ) if not title or html.find(u"<html") == -1: #$NON-NLS-1$ # case where only the body content is given or the content did not have non-empty <head> and <title> elems. # try and create wrapper around the body. Eg: <html><head><title>ZoundryDocument</title></head><body> CONTENT </body> </html> html = wrapHtmlBody(html, u"ZoundryDocument") #$NON-NLS-1$ # note: \r\n must be replace with \n. Otherwise, in <pre> blocks, the \r' will show up as an extra line. html = html.replace(u"\r\n", u"\n") #$NON-NLS-1$ #$NON-NLS-2$ # For the test-harness to work, hard code temp dir tmpDir = u"c:/temp" #$NON-NLS-1$ if getApplicationModel(): userProfile = getApplicationModel().getUserProfile() tmpDir = userProfile.getTempDirectory() d = str(time.time()) fname = os.path.join(tmpDir, u"_z_raven_mshtml_%s_tmp.xhtml" % d) #$NON-NLS-1$ tmpFile = codecs.open(fname, u"w") #$NON-NLS-1$ try: # write the utf-8 byte order marker for wintel platforms. tmpFile.write(codecs.BOM_UTF8) tmpFile.write( convertToUtf8(html) ) tmpFile.close() self._loadFile(fname) finally: tmpFile.close()
def _prepareForLoading(self, xhtmlString): u"""Prepares the raw xhtml string for loading into zDom.""" #$NON-NLS-1$ xhtmlString = xhtmlString.lstrip() if xhtmlString.startswith(u"<!DOCTYPE"): #$NON-NLS-1$ xhtmlString = xhtmlString[xhtmlString.find(u">") + 1:] #$NON-NLS-1$ xhtmlString = xhtmlString.replace(u' ', u' ') #$NON-NLS-1$ #$NON-NLS-2$ (bOk, xhtmlString) = self._cleanupMsOffice(xhtmlString) #@UnusedVariable # if the string content does not have a <body/> then convert to xhtml and wrap it # with <html><body/></html> if not xhtmlutil.hasBody(xhtmlString): if not xhtmlutil.hasXhtmlMarkup(xhtmlString): self.messages.append(u"Converting plain text to xhtml markup.") #$NON-NLS-1$ # convert plain text to xhtml transformer = ZTextToXhtmlTransformer() xhtmlString = transformer.transform(xhtmlString) xhtmlString = xhtmlutil.wrapHtmlBody(xhtmlString) self.messages.append(u"Adding <html><body></body></html> wrapper.") #$NON-NLS-1$ return xhtmlString
def _loadStringFromFile(self, html): # MSHTML control requires a <head> and <title> element title = getNoneString(extractTitle(html)) if not title or html.find(u"<html") == -1: #$NON-NLS-1$ # case where only the body content is given or the content did not have non-empty <head> and <title> elems. # try and create wrapper around the body. Eg: <html><head><title>ZoundryDocument</title></head><body> CONTENT </body> </html> html = wrapHtmlBody(html, u"ZoundryDocument") #$NON-NLS-1$ # note: \r\n must be replace with \n. Otherwise, in <pre> blocks, the \r' will show up as an extra line. html = html.replace(u"\r\n", u"\n") #$NON-NLS-1$ #$NON-NLS-2$ # For the test-harness to work, hard code temp dir tmpDir = u"c:/temp" #$NON-NLS-1$ if getApplicationModel(): userProfile = getApplicationModel().getUserProfile() tmpDir = userProfile.getTempDirectory() d = str(time.time()) # For Microsoft Internet Explorer Version 9 (and above?) the file extension for the temporary file must have # a ".html" (previously a ".xhtml") extension in order for the blog post to load successfully into the ActiveX # mshtml IHtmlDocument. Otherwise, the blog posts will appear to be mal-formatted during previews and fail to # load correctly during editing. # # Chuah TC 23 December 2013 # #fname = os.path.join(tmpDir, u"_z_raven_mshtml_%s_tmp.xhtml" % d) #$NON-NLS-1$ fname = os.path.join(tmpDir, u"_z_raven_mshtml_%s_tmp.html" % d) #$NON-NLS-1$ tmpFile = codecs.open(fname, u"w") #$NON-NLS-1$ try: # write the utf-8 byte order marker for wintel platforms. tmpFile.write(codecs.BOM_UTF8) tmpFile.write(convertToUtf8(html)) tmpFile.close() self._loadFile(fname) finally: tmpFile.close()