Ejemplo n.º 1
0
 def s_html_fontstyle(self, tag, attrs):
     """ 15.2.1 Font style elements: the TT, I, B, BIG, SMALL,
         STRIKE, S, and U elements
         ('tt' is not considered an automatic style by OOo)
     """
     tagdict = {
        'b':      ['BoldX',{'fontweight':"bold",
                   'fontweightasian':"bold",'fontweightcomplex':"bold" }],
        'big':    ['BigX', {'fontsize':"120%"}],
        'i':      ['ItalicX', {'fontstyle':"italic", 'fontstyleasian':"italic", 'fontstylecomplex':"italic" }],
        'tt':     ['TeletypeX', {'fontname':"Courier", 'fontnameasian':"Courier", 'fontnamecomplex':"Courier" }],
        's':      ['StrikeX', {'textlinethroughstyle':"solid"}],
        'small':  ['SmallX', {'fontsize':"80%"}],
        'strike': ['StrikeX', {'textlinethroughstyle':"solid"}],
        'u':      ['UnderlineX', {'textunderlinestyle':"solid", 'textunderlinewidth':"auto",
                   'textunderlinecolor':"fontcolor"}],
     }
     stylename,styledecl = tagdict.get(tag,[None,None])
     if stylename and self.doc.getStyleByName(stylename) is None:
         style = Style(name=stylename, family="text")
         style.addElement(TextProperties(attributes=styledecl))
         self.doc.automaticstyles.addElement(style)
     if stylename:
         e = text.Span(stylename=stylename)
     else:
         e = text.Span()
     self.curr.addElement(e)
     self.curr = e
Ejemplo n.º 2
0
    def dset_sheet(cls, dataset, ws):
        """Completes given worksheet from given Dataset."""
        _package = dataset._package(dicts=False)

        for i, sep in enumerate(dataset._separators):
            _offset = i
            _package.insert((sep[0] + _offset), (sep[1], ))

        for i, row in enumerate(_package):
            row_number = i + 1
            odf_row = table.TableRow(stylename=bold,
                                     defaultcellstylename='bold')
            for j, col in enumerate(row):
                try:
                    col = str(col, errors='ignore')
                except TypeError:
                    # col is already str
                    pass
                ws.addElement(table.TableColumn())

                # bold headers
                if (row_number == 1) and dataset.headers:
                    odf_row.setAttribute('stylename', bold)
                    ws.addElement(odf_row)
                    cell = table.TableCell()
                    p = text.P()
                    p.addElement(text.Span(text=col, stylename=bold))
                    cell.addElement(p)
                    odf_row.addElement(cell)

                # wrap the rest
                else:
                    try:
                        if '\n' in col:
                            ws.addElement(odf_row)
                            cell = table.TableCell()
                            cell.addElement(text.P(text=col))
                            odf_row.addElement(cell)
                        else:
                            ws.addElement(odf_row)
                            cell = table.TableCell()
                            cell.addElement(text.P(text=col))
                            odf_row.addElement(cell)
                    except TypeError:
                        ws.addElement(odf_row)
                        cell = table.TableCell()
                        cell.addElement(text.P(text=col))
                        odf_row.addElement(cell)
Ejemplo n.º 3
0
def addparagraph(section):
    """ Join the paragraph list and add it to the section
    """
    global paragraph

    p = ' '.join(paragraph)
    textsegs = p.split('_')
    para = text.P(stylename=textbodystyle)
    section.addElement(para)
    if len(textsegs) > 1 and (len(textsegs) % 2) == 1:
        # We have found some kursive text segments
        for i in range(len(textsegs)):
            if len(textsegs[i]) > 0:
                if (i % 2) == 1:
                    y = text.Span(stylename=emphasisstyle, text=textsegs[i])
                    para.addElement(y)
                else:
                    para.addText(textsegs[i])
    else:
        para.addText(p)
Ejemplo n.º 4
0
 def owriteInserted(self, obj): 
     return text.Span(stylename=style.inserted)
Ejemplo n.º 5
0
 def owriteDeleted(self, obj): 
     return text.Span(stylename=style.deleted)
Ejemplo n.º 6
0
           'cite':      ['Citation', {'fontstyle':"italic", 'fontstyleasian':"italic", 'fontstylecomplex':"italic" }],
           'code':      ['Source_20_Text', {'fontname':"Courier", 'fontnameasian':"Courier",'fontnamecomplex':"Courier" }],
           'dfn':      ['Definition',{ }],
           'em':      ['Emphasis', {'fontstyle':"italic", 'fontstyleasian':"italic", 'fontstylecomplex':"italic" }],
           'strong':   ['Strong_20_Emphasis': {'fontweight':"bold",'fontweightasian':"bold",'fontweightcomplex':"bold"}],
           'var':      ['Variable', {'fontstyle':"italic", 'fontstyleasian':"italic", 'fontstylecomplex':"italic" }],
           }
        stylename = tagdict.get(tag,'Emphasis')
        # Add the styles we need to the stylesheet
        if stylename == "Source_20_Text" and self.doc.getStyleByName(stylename) is None:
            style = Style(name="Source_20_Text", displayname="Source Text", family="text")
            p = TextProperties(fontname="Courier", fontnameasian="Courier", fontnamecomplex="Courier")
            style.addElement(p)
            self.doc.styles.addElement(style)

        e = text.Span(stylename=stylename)
        self.curr.addElement(e)
        self.curr = e

    def s_html_fontstyle(self, tag, attrs):
        """ 15.2.1 Font style elements: the TT, I, B, BIG, SMALL,
            STRIKE, S, and U elements
            ('tt' is not considered an automatic style by OOo)
        """
        tagdict = {
           'b':      ['BoldX',{'fontweight':"bold",
                      'fontweightasian':"bold",'fontweightcomplex':"bold" }],
           'big':    ['BigX', {'fontsize':"120%"}],
           'i':      ['ItalicX', {'fontstyle':"italic", 'fontstyleasian':"italic", 'fontstylecomplex':"italic" }],
           'tt':     ['TeletypeX', {'fontname':"Courier", 'fontnameasian':"Courier", 'fontnamecomplex':"Courier" }],
           's':      ['StrikeX', {'textlinethroughstyle':"solid"}],
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
 def owriteTeletyped(self, obj):
     # (monospaced) or code, newlines ignored, spaces collapsed
     return text.Span(stylename=style.teletyped)
Ejemplo n.º 9
0
 def owriteStrike(self, s):
     return text.Span(stylename=style.strike)
Ejemplo n.º 10
0
 def owriteOverline(self, s):
     return text.Span(stylename=style.overline)
Ejemplo n.º 11
0
 def owriteStrong(self, obj):
     return text.Span(stylename=style.strong)
Ejemplo n.º 12
0
 def owriteEmphasized(self, obj):
     return text.Span(stylename=style.emphasis)
Ejemplo n.º 13
0
 def testTextStyleName(self):
     """ Test that you can use the name of the style in references """
     boldstyle = style.Style(name=u"Bold", family=u"text")
     boldstyle.addElement(
         style.TextProperties(attributes={u'fontweight': u"bold"}))
     text.Span(stylename=u"Bold", text=u"This part is bold. ")
Ejemplo n.º 14
0
 def s_html_span(self, tag, attrs):
     e = text.Span()
     self.curr.addElement(e)
     self.curr = e
Ejemplo n.º 15
0
 def owriteSup(self, obj): 
     return text.Span(stylename=style.sup)
Ejemplo n.º 16
0
 def owriteSpan(self, obj): 
     return text.Span()
Ejemplo n.º 17
0
 def owriteBold(self, obj):
     return text.Span(stylename=style.bold)
Ejemplo n.º 18
0
 def owriteUnderline(self, s):
     return text.Span(stylename=style.underline)
Ejemplo n.º 19
0
 def owriteItalic(self, obj):
     return text.Span(stylename=style.italic)
Ejemplo n.º 20
0
 def owriteCite(self, obj): 
     return text.Span(stylename=style.cite)
Ejemplo n.º 21
0
 def owriteSmall(self, obj): 
     return text.Span(stylename=style.small)
Ejemplo n.º 22
0
 def owriteCode(self, obj): 
     return text.Span(stylename=style.code)
Ejemplo n.º 23
0
 def owriteBig(self, obj): 
     return text.Span(stylename=style.big)
Ejemplo n.º 24
0
 def owriteVar(self, obj): 
     return text.Span(stylename=style.var)
Ejemplo n.º 25
0
    h3.addText(classname)
    h3.addElement(text.BookmarkEnd(name=classname))
    section.addElement(h3)

    # Required attributes
    p = text.P(text="Requires the following attributes: ")
    required_attributes = grammar.required_attributes.get(element)
    if required_attributes is None:
        info = "No attribute is required"
    elif required_attributes is ():
        info = "No attribute is required"
    else:
        required_args = [ a[1].lower().replace('-','') for a in required_attributes]
        required_args.sort()
        info = ', '.join(required_args)
    p.addElement(text.Span(stylename=attrliststyle, text=info+"."))
    section.addElement(p)

    # Allowed attributes
    p = text.P(text="Allows the following attributes: ")
    allowed_attrs = grammar.allowed_attributes.get(element)
    if allowed_attrs is None:
        info = "No attribute is allowed"
    elif allowed_attrs is ():
        info = "No attribute is allowed"
    else:
        allowed_args = [ a[1].lower().replace('-','') for a in allowed_attrs]
        allowed_args.sort()
        info = ', '.join(allowed_args)
    p.addElement(text.Span(stylename=attrliststyle, text=info))
    p.addText(".")