def _createContentNodeFromTextData(self, parentNode): if self.xmlFormat: # append xml/xhtml fragment contentNode = createHtmlElement(parentNode, u"div") #$NON-NLS-1$ appendHtmlFragment(contentNode, self.izBlogThisInformation.getText()) else: # append simple text content contentNode = createHtmlElement(parentNode, u"p", elementText = self.izBlogThisInformation.getText()) #$NON-NLS-1$ return contentNode
def _createLink(self, attrMap): attrs = attrMap.copy() linkText = None if attrs.has_key(u"text"): #$NON-NLS-1$ linkText = getNoneString(attrs[u"text"]) #$NON-NLS-1$ del attrs[u"text"] #$NON-NLS-1$ selectedElem = self.mshtmlEditControl._getMshtmlControl().getSelectedElement() replaceTextPattern = u"${_zraven_link_child_nodes_}$" #$NON-NLS-1$ if selectedElem: textRange = self.mshtmlEditControl._getMshtmlControl().getSelectedTextRange() linkNode = createHtmlElement(None, u"a", attrs, replaceTextPattern) #$NON-NLS-1$ linkNodeHtml = linkNode.serialize() if textRange: if linkText and linkText != textRange.text: # replace link text if textRange.htmlText == textRange.text: # simple text selection newText = linkNodeHtml.replace(replaceTextPattern, linkText) textRange.pasteHTML(newText) else: # has html (img) + text. replace only the text. s = textRange.htmlText # replace the current text with the new link text s = s.replace(textRange.text, linkText) # wrap in <a> newText = linkNodeHtml.replace(replaceTextPattern, s) else: if textRange.htmlText and selectedElem.outerHTML == textRange.htmlText: newText = linkNodeHtml.replace(replaceTextPattern, selectedElem.innerHTML) selectedElem.innerHTML = newText elif textRange.htmlText and selectedElem.innerHTML == textRange.htmlText: newText = linkNodeHtml.replace(replaceTextPattern, selectedElem.innerHTML) selectedElem.innerHTML = newText elif textRange.htmlText: newText = linkNodeHtml.replace(replaceTextPattern, textRange.htmlText) textRange.pasteHTML(newText) else: newText = linkNodeHtml.replace(replaceTextPattern, selectedElem.innerHTML) selectedElem.innerHTML = newText else: if linkText: selectedElem.innerText = linkText newHtml = linkNodeHtml.replace(replaceTextPattern, selectedElem.outerHTML) selectedElem.outerHTML = newHtml else: # if text is not provided, then use the link location as the text. if not linkText: linkText = unquote(attrs[u"href"]) #$NON-NLS-1$ linkNode = createHtmlElement(None,u"a",attrs, linkText) #$NON-NLS-1$ linkNodeHtml = linkNode.serialize() self.mshtmlEditControl._getMshtmlControl().insertHtml(linkNodeHtml)
def _createContentNodeFromTextData(self, parentNode): if self.xmlFormat: # append xml/xhtml fragment contentNode = createHtmlElement(parentNode, u"div") #$NON-NLS-1$ appendHtmlFragment(contentNode, self.izBlogThisInformation.getText()) else: # append simple text content contentNode = createHtmlElement( parentNode, u"p", elementText=self.izBlogThisInformation.getText()) #$NON-NLS-1$ return contentNode
def _handleFileList(self, fileList): if not fileList: return None rootEle = None if len(fileList) == 1: rootEle = self._createFileAnchorElement(fileList[0], None) else: rootEle = createHtmlElement(None, u"p") #$NON-NLS-1$ for fileName in fileList: self._createFileAnchorElement(fileName, rootEle) createHtmlElement(rootEle, u"br") #$NON-NLS-1$ xhtmlDom = loadXhtmlDocumentFromDOM(rootEle) return xhtmlDom
def _createFileAnchorElement(self, fileName, parentElement): # check if this is a url shortcut size = 0 rel = None (url, shortName) = getUrlFromShortcut(fileName) if not url: # local file (url, shortName, absPath, size, schemaDate) = self._getFileMetaData(fileName) #@UnusedVariable if not shortName: shortName = url linkText = shortName linkTitle = shortName if size > 0: rel = u"enclosure" #$NON-NLS-1$ linkTitle = linkTitle + u" (%s)" % self._getFileSizeString( size) #$NON-NLS-1$ attrs = {} attrs[u"title"] = linkTitle #$NON-NLS-1$ attrs[u"href"] = url #$NON-NLS-1$ if rel: attrs[u"rel"] = rel #$NON-NLS-1$ elem = createHtmlElement(parentElement, u"a", attrs, linkText) #$NON-NLS-1$ return elem
def _createFileAnchorElement(self, fileName, parentElement): # check if this is a url shortcut size = 0 rel = None (url, shortName) = getUrlFromShortcut(fileName) if not url: # local file (url, shortName, absPath, size, schemaDate) = self._getFileMetaData(fileName) #@UnusedVariable if not shortName: shortName = url linkText = shortName linkTitle = shortName if size > 0: rel = u"enclosure" #$NON-NLS-1$ linkTitle = linkTitle + u" (%s)" % self._getFileSizeString(size) #$NON-NLS-1$ attrs = {} attrs[u"title"] = linkTitle #$NON-NLS-1$ attrs[u"href"] = url #$NON-NLS-1$ if rel: attrs[u"rel"] = rel #$NON-NLS-1$ elem = createHtmlElement(parentElement, u"a", attrs, linkText) #$NON-NLS-1$ return elem
def _createXhtmlContent(self, bodyNode): # create <p> createHtmlElement(bodyNode, u"p") #$NON-NLS-1$ # build content # 1: if url is given, then add "cited" content if getNoneString( self.izBlogThisInformation.getUrl() ): # self._createContentNodeFromUrlData(bodyNode) elif getNoneString(self.izBlogThisInformation.getText()): # content given as text (plain or xhtml) data. self._createContentNodeFromTextData(bodyNode) elif getNoneString( self.izBlogThisInformation.getTitle() ): # only the title is available createHtmlElement(bodyNode, u"p", elementText = self.izBlogThisInformation.getTitle() ) #$NON-NLS-1$ # create trailing para createHtmlElement(bodyNode, u"p") #$NON-NLS-1$
def _createXhtmlContent(self, bodyNode): # create <p> createHtmlElement(bodyNode, u"p") #$NON-NLS-1$ # build content # 1: if url is given, then add "cited" content if getNoneString(self.izBlogThisInformation.getUrl()): # self._createContentNodeFromUrlData(bodyNode) elif getNoneString(self.izBlogThisInformation.getText()): # content given as text (plain or xhtml) data. self._createContentNodeFromTextData(bodyNode) elif getNoneString(self.izBlogThisInformation.getTitle()): # only the title is available createHtmlElement(bodyNode, u"p", elementText=self.izBlogThisInformation.getTitle( )) #$NON-NLS-1$ # create trailing para createHtmlElement(bodyNode, u"p") #$NON-NLS-1$
def _createContentNodeFromUrlData(self, parentNode): # create content data base one blog post or web site data including 'cite' element # and a link back to original document url = getSafeString(self.izBlogThisInformation.getUrl()) title = self._escape(self.izBlogThisInformation.getTitle()) text = getNoneString(self.izBlogThisInformation.getText()) author = getNoneString(self.izBlogThisInformation.getAuthor()) # default title to permanent link citeTitle = url if title and title != url: citeTitle = title contentNode = createHtmlElement(parentNode, u"p") #$NON-NLS-1$ if text: # since content is given, create content in <cite> element if author: citeTitle = citeTitle + u" (" + author + u")" #$NON-NLS-1$ #$NON-NLS-2$ citeTitle = citeTitle + u": " #$NON-NLS-1$ citeNode = createHtmlElement(contentNode, u"cite") #$NON-NLS-1$ attrs = {u"href": url} #$NON-NLS-1$ if citeTitle != url: attrs[u"title"] = citeTitle #$NON-NLS-1$ # create a <a href="url">citeTitle</a> inside the cite element createHtmlElement(citeNode, u"a", attrs, citeTitle) #$NON-NLS-1$ innerContentNode = parentNode # block quote if needed, then wrap the content node in a blockquote. if self.izBlogThisInformation.isQuoted(): attrs = {u"cite": url} #$NON-NLS-1$ innerContentNode = createHtmlElement(innerContentNode, u"blockquote", attrs) #$NON-NLS-1$ if self.xmlFormat: innerContentNode = createHtmlElement(innerContentNode, u"div", attrs) #$NON-NLS-1$ appendHtmlFragment(innerContentNode, text) else: createHtmlElement(innerContentNode, u"p", elementText=text) #$NON-NLS-1$ else: # content is not given. in this case, simply create a link to the url attrs = {u"href": url} #$NON-NLS-1$ createHtmlElement(contentNode, u"a", attrs, citeTitle) #$NON-NLS-1$ createHtmlElement(contentNode, u"br") #$NON-NLS-1$ return contentNode
def _createContentNodeFromUrlData(self, parentNode): # create content data base one blog post or web site data including 'cite' element # and a link back to original document url = getSafeString( self.izBlogThisInformation.getUrl() ) title = self._escape( self.izBlogThisInformation.getTitle() ) text = getNoneString(self.izBlogThisInformation.getText()) author = getNoneString(self.izBlogThisInformation.getAuthor()) # default title to permanent link citeTitle = url if title and title != url: citeTitle = title contentNode = createHtmlElement(parentNode, u"p") #$NON-NLS-1$ if text: # since content is given, create content in <cite> element if author: citeTitle = citeTitle + u" (" + author + u")" #$NON-NLS-1$ #$NON-NLS-2$ citeTitle = citeTitle + u": " #$NON-NLS-1$ citeNode = createHtmlElement(contentNode, u"cite") #$NON-NLS-1$ attrs = { u"href" : url } #$NON-NLS-1$ if citeTitle != url: attrs[u"title"] = citeTitle #$NON-NLS-1$ # create a <a href="url">citeTitle</a> inside the cite element createHtmlElement(citeNode, u"a", attrs, citeTitle) #$NON-NLS-1$ innerContentNode = parentNode # block quote if needed, then wrap the content node in a blockquote. if self.izBlogThisInformation.isQuoted(): attrs = { u"cite" : url } #$NON-NLS-1$ innerContentNode = createHtmlElement(innerContentNode, u"blockquote", attrs) #$NON-NLS-1$ if self.xmlFormat: innerContentNode = createHtmlElement(innerContentNode, u"div", attrs) #$NON-NLS-1$ appendHtmlFragment(innerContentNode, text) else: createHtmlElement(innerContentNode, u"p", elementText = text) #$NON-NLS-1$ else: # content is not given. in this case, simply create a link to the url attrs = { u"href" : url } #$NON-NLS-1$ createHtmlElement(contentNode,u"a", attrs, citeTitle) #$NON-NLS-1$ createHtmlElement(contentNode,u"br") #$NON-NLS-1$ return contentNode