def dumpContent(self, content): '''Dumps string p_content into the buffer.''' if self.pod: # Take care of converting line breaks and tabs. content = escapeXml(content, format='odf', nsText=self.env.namespaces[self.env.NS_TEXT]) else: content = escapeXml(content) self.write(content)
def dumpCurrentContent(self, place, elem): '''Dumps content that was temporarily stored in self.currentContent into the result.''' contentSize = 0 # Remove the trailing whitespace if needed if place == 'start': if self.currentContent.endswith(' ') and \ ((elem not in INNER_TAGS) or (elem == 'br')): self.currentContent = self.currentContent[:-1] # Remove the leading whitespace if needed if self.currentContent.startswith(' '): if not self.lastElem or \ ((self.lastElem not in INNER_TAGS) or (self.lastElem == 'br')): self.currentContent = self.currentContent[1:] if self.currentContent: # Manage missing elements currentElem = self.getCurrentElement() if self.anElementIsMissing(currentElem, None): currentElem.addInnerParagraph(self) # Dump and reinitialize the current content contentSize = len(self.currentContent) self.dumpString(escapeXml(self.currentContent)) self.currentContent = '' # If we are within a table cell, update the total size of cell content if not contentSize: return if self.currentTables and self.currentTables[-1].inCell: for table in self.currentTables: table.cellContentSize += contentSize
def startElement(self, elem, attrs): elem, attrs = self.lowerizeInput(elem, attrs) e = XmlParser.startElement(self, elem, attrs) currentElem = e.onElementStart(elem, attrs) odfTag = currentElem.getOdfTag(e) if HTML_2_ODT.has_key(elem): e.dumpStyledElement(currentElem, odfTag, attrs) elif elem == 'a': e.dumpString('<%s %s:type="simple"' % (odfTag, e.linkNs)) if attrs.has_key('href'): e.dumpString(' %s:href="%s"' % (e.linkNs, escapeXml(attrs['href']))) e.dumpString('>') elif elem in XHTML_LISTS: prologue = '' if len(e.currentLists) >= 2: # It is a list into another list. In this case the inner list # must be surrounded by a list-item element. prologue = '<%s:list-item>' % e.textNs numbering = '' if elem == 'ol': numbering = ' %s:continue-numbering="false"' % e.textNs e.dumpString( '%s<%s %s:style-name="%s"%s>' % (prologue, odfTag, e.textNs, e.listStyles[elem], numbering)) elif elem in ('li', 'thead', 'tr'): e.dumpString('<%s>' % odfTag) elif elem == 'table': # Here we must call "dumpString" only once table = e.currentTables[-1] e.dumpString('<%s %s:name="%s" %s:style-name="podTable">' % \ (odfTag, e.tableNs, table.name, e.tableNs)) elif elem in TABLE_CELL_TAGS: e.dumpString('<%s %s:style-name="%s"' % \ (odfTag, e.tableNs, DEFAULT_ODT_STYLES[elem])) if attrs.has_key('colspan'): e.dumpString(' %s:number-columns-spanned="%s"' % \ (e.tableNs, attrs['colspan'])) e.dumpString('>') elif elem == 'img': style = None if attrs.has_key('style'): style = attrs['style'] imgCode = e.renderer.importDocument(at=attrs['src'], wrapInPara=False, style=style) e.dumpString(imgCode) elif elem in IGNORABLE_TAGS: e.ignore = True
def startElement(self, elem, attrs): elem, attrs = self.lowerizeInput(elem, attrs) e = XmlParser.startElement(self, elem, attrs) currentElem = e.onElementStart(elem, attrs) odfTag = currentElem.getOdfTag(e) if HTML_2_ODT.has_key(elem): e.dumpStyledElement(currentElem, odfTag, attrs) elif elem == 'a': e.dumpString('<%s %s:type="simple"' % (odfTag, e.linkNs)) if attrs.has_key('href'): e.dumpString(' %s:href="%s"' % (e.linkNs, escapeXml(attrs['href']))) e.dumpString('>') elif elem in XHTML_LISTS: prologue = '' if len(e.currentLists) >= 2: # It is a list into another list. In this case the inner list # must be surrounded by a list-item element. prologue = '<%s:list-item>' % e.textNs numbering = '' if elem == 'ol': numbering = ' %s:continue-numbering="false"' % e.textNs e.dumpString('%s<%s %s:style-name="%s"%s>' % ( prologue, odfTag, e.textNs, e.listStyles[elem], numbering)) elif elem in ('li', 'thead', 'tr'): e.dumpString('<%s>' % odfTag) elif elem == 'table': # Here we must call "dumpString" only once table = e.currentTables[-1] e.dumpString('<%s %s:name="%s" %s:style-name="podTable">' % \ (odfTag, e.tableNs, table.name, e.tableNs)) elif elem in TABLE_CELL_TAGS: e.dumpString('<%s %s:style-name="%s"' % \ (odfTag, e.tableNs, DEFAULT_ODT_STYLES[elem])) if attrs.has_key('colspan'): e.dumpString(' %s:number-columns-spanned="%s"' % \ (e.tableNs, attrs['colspan'])) e.dumpString('>') elif elem == 'img': style = None if attrs.has_key('style'): style = attrs['style'] imgCode = e.renderer.importDocument(at=attrs['src'], wrapInPara=False, style=style) e.dumpString(imgCode) elif elem in IGNORABLE_TAGS: e.ignore = True
def startElement(self, elem, attrs): e = OdfParser.startElement(self, elem, attrs) # Do we enter into an annotation ? if elem == '%s:annotation' % e.ns(e.NS_OFFICE): self.inAnnotation = True self.textEncountered = False elif elem == '%s:p' % e.ns(e.NS_TEXT): if self.inAnnotation: if not self.textEncountered: self.textEncountered = True else: self.ignore = True if not self.ignore: self.res += '<%s' % elem for attrName, attrValue in attrs.items(): self.res += ' %s="%s"' % \ (attrName, escapeXml(attrValue, escapeApos=True)) self.res += '>'
def dumpCurrentContent(self): '''Dumps content that was temporarily stored in self.currentContent into the result.''' contentSize = 0 if self.currentContent.strip(): # Manage missing elements currentElem = self.getCurrentElement() if self.anElementIsMissing(currentElem, None): currentElem.addInnerParagraph(self) # Dump and reinitialize the current content content = self.currentContent.strip('\n\t') # We remove leading and trailing carriage returns, but not # whitespace because whitespace may be part of the text to dump. contentSize = len(content) self.dumpString(escapeXml(content)) self.currentContent = u'' # If we are within a table cell, update the total size of cell content. if self.currentTables and self.currentTables[-1].inCell: for table in self.currentTables: table.cellContentSize += contentSize
def characters(self, content): e = OdfParser.characters(self, content) if not self.ignore: self.res += escapeXml(content)
def dumpContent(self, content): '''Dumps string p_content into the buffer.''' self.write(escapeXml(content))
def dumpContent(self, content): """Dumps string p_content into the buffer.""" self.write(escapeXml(content))