Ejemplo n.º 1
0
    def parsePRETag(self):
        token = self.token[0]
        if token.t.lower() == 'pre':
            n = PreFormatted()
        else:
            n = TagNode(token.t)
            n.starttext = ''
            n.endtext = ''

        n.vlist = parseParams(self.token[1])

        end = EndTagToken(self.token[0].t)
        self.next()

        txt = []
        while self.left:
            token = self.token
            if token[0] == end:
                self.next()
                break
            txt.append(token[1])
            self.next()

        n.append(Text("".join(txt)))
        return n
Ejemplo n.º 2
0
    def parseTag(self):
        token = self.token[0]

        n = TagNode(token.t)
        if token.values:
            n.values = token.values
        n.vlist = parseParams(self.token[1])

        n.starttext = token.text
        n.endtext = u'</%s>' % token.t
        self.next()

        if token.selfClosing:
            return n

        end = EndTagToken(token.t)

        while self.left:
            token = self.token
            if token[0] == end:
                n.endtext = token[0].text
                self.next()
                break
            elif token[0] == 'BREAK':
                self.next()
            else:
                if token[0] not in FirstParagraph:
                    log.warn("tag not closed", n, token)
                    break
                n.append(self.parseParagraph())

        return n
Ejemplo n.º 3
0
    def parseLITag(self):

        p = item = Item()

        p.vlist = parseParams(self.token[1])

        self.next()
        break_at = TokenSet([EndTagToken, 'ENDTABLE', 'SECTION'])
        while self.left:
            token = self.token
            if token[0] == '\n':
                p.append(Text(token[1]))
                self.next()
            elif token[0] == 'EOLSTYLE':
                p.append(self.parseEOLStyle())
            elif token[0] == 'BREAK':
                append_br_tag(p)
                self.next()
            elif token[0] == tag_li:
                break
            elif token[0] == EndTagToken("li"):
                self.next()
                break
            elif token[0] in break_at:
                break
            elif token[0] in FirstAtom:
                p.append(self.parseAtom())
            else:
                log.info("in parseLITag: assuming text", token)
                p.append(Text(token[1]))
                self.next()

        return item
Ejemplo n.º 4
0
    def _parseStyledTag(self, style=None):

        token = self.token[0]
        if style is None:
            style = Style(token.t)

        b = style
        end = EndTagToken(token.t)
        start = TagToken(token.t)
        self.next()

        if token.selfClosing:
            return style

        break_at = set([
            "ENDTABLE", "ROW", "COLUMN", "ITEM", "BREAK", "SECTION",
            "BEGINTABLE"
        ])

        while self.left:
            token = self.token
            if token[0] in break_at:
                break
            elif token[0] == '\n':
                b.append(Text(token[1]))
                self.next()
            elif token[0] == end:
                self.next()
                break
            elif isinstance(token[0], EndTagToken):
                break
            elif isinstance(token[0], TagToken):
                if token[0] == start:
                    self.next()  # 'Nuclear fuel' looks strange otherwise
                    break
                b.append(self.parseTagToken())
            elif token[0] in FirstAtom:
                b.append(self.parseAtom())
            else:
                log.info("_parseStyledTag: assuming text", token)
                b.append(Text(token[1]))
                self.next()

        return b
Ejemplo n.º 5
0
    def _parseHTMLList(self, numbered):
        lst = ItemList()
        lst.numbered = numbered

        end = EndTagToken(self.token[0].t)

        self.next()
        while self.left:
            token = self.token
            if token[0] == end:
                self.next()
                break
            elif isinstance(token[0], TagToken):
                lst.append(self.parseTagToken())
            elif token[0] == 'ITEM':
                lst.append(self.parseItemList())
            elif token[0] in FirstAtom:
                lst.append(self.parseAtom())
            else:
                log.info("assuming text in _parseHTMLList", token)
                lst.append(Text(token[1]))
                self.next()

        return lst