def owriteTable(self, obj): # FIXME ADD FORMATTING # http://books.evc-cit.info/odbook/ch04.html#text-table-section t = table.Table() tc = table.TableColumn(stylename=style.dumbcolumn, numbercolumnsrepeated=str( obj.numcols)) # FIXME FIXME t.addElement(tc) captions = [c for c in obj.children if isinstance(c, advtree.Caption)] if not captions: # handle table w/o caption: return t else: # a section groups table-caption & table: if not len(captions) == 1: log("owriteTable: more than one Table Caption not handeled. Using only first Caption!" ) # group using a section sec = text.Section(stylename=style.sectTable, name="table section") p = ParagraphProxy(stylename=style.tableCaption) sec.addElement(p) self.writeChildren(captions[0], p) # only one caption expected and allowed sec.addElement(t) sec.writeto = t return sec
def owriteArticle(self, a): self.references = [] # collect references title = a.caption log(u"processing article %s" % title) r = text.Section(stylename=style.sect, name=title) #, display="none") r.addElement( text.H(outlinelevel=1, stylename=style.ArticleHeader, text=title)) return r
def s_html_section(self, tag, attrs): """ Outputs block tag such as <p> and <div> """ name = self.find_attr(attrs,'id') if name is None: self.sectnum = self.sectnum + 1 name = "Sect%d" % self.sectnum e = text.Section(name=name) self.curr.addElement(e) self.curr = e
def owriteSection(self, obj): hXstyles = (style.h0,style.h1,style.h2,style.h3,style.h4,style.h5) # skip empty sections (as for eg References) hasDisplayContent = u"".join(x.getAllDisplayText().strip() for x in obj.children [1:]) \ or obj.getChildNodesByClass(advtree.ImageLink) # FIXME, add AdvancedNode.hasContent property enabled = False if enabled and not hasDisplayContent: # FIXME return SkipChildren() title = obj.children[0].getAllDisplayText() # = is level 0 as in article title = # == is level 1 as in mediawiki top level section == # getSectionLevel() == 1 for most outer section level level = 1 + obj.getSectionLevel() # min: 1+0 = 1 level = min(level, len(hXstyles)) hX = hXstyles[level-1] r = text.Section(stylename=style.sect, name=title) r.addElement(text.H(outlinelevel=level, stylename=hX, text=title)) obj.children = obj.children[1:] return r
def html2odf(e, ct=None, **ctargs): """ Convert a :mod:`etgen.html` element to an ODF text element. Most formats are not implemented. There's probably a better way to do this... :ct: the root element ("container"). If not specified, we create one. """ sections_counter = 1 #~ print "20120613 html2odf()", e.tag, e.text if ct is None: ct = text.P(**ctargs) #~ if e.tag in PTAGS: #~ oe = text.P(**ctargs) #~ else: #~ oe = text.P(**ctargs) #~ logger.info("20130201 %s", tostring(e)) #~ raise NotImplementedError("<%s> without container" % e.tag) if isinstance(e, six.string_types): ct.addText(e) #~ oe = text.Span() #~ oe.addText(e) #~ yield oe return ct if e.tag == 'ul': ct = text.List(stylename='podBulletedList') ctargs = dict(stylename='podBulletItem') #~ ctargs = dict() text_container = None if e.tag in ('b', 'strong'): #~ oe = text.Span(stylename='Bold Text') oe = text.Span(stylename='Strong Emphasis') elif e.tag == 'a': oe = text.Span(stylename='Strong Emphasis') #~ oe = text.Span(stylename='Bold Text') elif e.tag in ('i', 'em'): oe = text.Span(stylename='Emphasis') elif e.tag == 'span': oe = text.Span() elif e.tag == 'br': oe = text.LineBreak() elif e.tag == 'h1': """ <text:h text:style-name="Heading_20_1" text:outline-level="1"> """ oe = ct = text.H(stylename="Heading 1", outlinelevel=1) elif e.tag == 'h2': oe = ct = text.H(stylename="Heading 2", outlinelevel=2) elif e.tag == 'h3': oe = ct = text.H(stylename="Heading 3", outlinelevel=3) elif e.tag == 'div': oe = ct = text.Section(name="S" + str(sections_counter)) elif e.tag == 'img': return # ignore images elif e.tag == 'ul': oe = ct #~ elif e.tag in ('ul','ol'): #~ oe = text.List(stylename=e.tag.upper()) #~ ctargs = dict(stylename=e.tag.upper()+"_P") elif e.tag == 'li': #~ oe = ct oe = text.ListItem() text_container = text.P(**ctargs) oe.appendChild(text_container) elif e.tag in PTAGS: oe = ct #~ if ct.tagName == 'p': #~ oe = ct #~ else: #~ oe = text.P(**ctargs) else: logger.info("20130201 %s", tostring(e)) raise NotImplementedError("<%s> inside <%s>" % (e.tag, ct.tagName)) #~ oe = text.Span() if text_container is None: text_container = oe if e.text: text_container.addText(e.text) for child in e: #~ html2odf(child,oe) html2odf(child, text_container, **ctargs) #~ for oc in html2odf(child,oe): # ~ # oe.addElement(oc) #~ oe.appendChild(oc) #~ if not True: #~ if e.tail: #~ oe.addText(e.tail) if oe is not ct: ct.appendChild(oe) #~ yield oe #~ if True: if e.tail: #~ yield e.tail #~ yield text.Span(text=e.tail) #~ yield Text(e.tail) ct.addText(e.tail) return ct
def owriteChapter(self, obj): title = obj.caption item = text.Section(stylename=style.sect, name=title) item.addElement( text.H(outlinelevel=1, text=title, stylename=style.chapter)) return item
if line == "by" or line == creator: section.addElement(text.P( stylename=subtitlestyle, text=cleantext(line))) return if len(paragraph) > 0: addparagraph(section) paragraph=[] section.addElement(text.P(stylename=textbodystyle, text=cleantext(line))) PRETEXT = 1 MAINPART = 2 POSTTEXT = 3 textpart = PRETEXT # Start in the preamble section = text.Section(stylename=sectstyle, name="preamble") #, display="none") textdoc.addElement(section) filename = args[0] if fn_is_title and title is not None and title != "": outfn = title else: suffixi = filename.rfind(".") if suffixi > 1: outfn = filename[:suffixi] else: outfn = "interimname" f = open(filename) for rawline in f: line = unicode(rawline.strip(), encoding)
#boldstyle = style.Style(name="Bold",family="text") #boldstyle.addElement(style.TextProperties(attributes={'fontweight':"bold"})) #textdoc.automaticstyles.addElement(boldstyle) attrliststyle = style.Style(name="Attribute List",family="text") attrliststyle.addElement(style.TextProperties(fontstyle="italic")) doc.styles.addElement(attrliststyle) elmliststyle = style.Style(name="Element List",family="text") elmliststyle.addElement(style.TextProperties(fontstyle="italic")) doc.styles.addElement(elmliststyle) # Text h = text.H(outlinelevel=1, stylename=h1style, text="API for odfpy") textdoc.addElement(h) section = text.Section(name="modules") textdoc.addElement(section) def elmcmp(e1, e2): n1 = nsdict[e1[0]] n2 = nsdict[e2[0]] if cmp(n1,n2) != 0: return cmp(n1,n2) return cmp(e1[1], e2[1]) childkeys = grammar.allowed_children.keys() childkeys.sort(elmcmp) ns='' for element in childkeys: children = grammar.allowed_children[element] if ns != nsdict[element[0]]: ns = nsdict[element[0]]