Ejemplo n.º 1
0
 def parse(self, stream):
     dn = self.rule.enter
     begin, end = '%s_begin' % dn, '%s_end' % dn
     stream.expect(begin)
     children = parse_child_nodes(stream, self, end)
     stream.expect(end)
     return self.__directive_node__(children)
Ejemplo n.º 2
0
 def parse(self, stream):
     dn = self.rule.enter
     begin, end = '%s_begin' % dn, '%s_end' % dn
     stream.expect(begin)
     children = parse_child_nodes(stream, self, end)
     stream.expect(end)
     return self.__directive_node__(children)
Ejemplo n.º 3
0
 def parse(self, stream):
     stream.expect('url_begin')
     href = stream.expect('url_source').value
     children = parse_child_nodes(stream, self, 'url_end')
     title = children and u''.join(n.text for n in children)
     if href is None:
         href = title
     stream.expect('url_end')
     return nodes.Link(href, children, title)
Ejemplo n.º 4
0
 def parse(self, stream):
     stream.expect('url_begin')
     href = stream.expect('url_source').value
     children = parse_child_nodes(stream, self, 'url_end')
     title = children and u''.join(n.text for n in children)
     if href is None:
         href = title
     stream.expect('url_end')
     return nodes.Link(href, children, title)
Ejemplo n.º 5
0
 def parse(self, stream):
     if stream.test('stroke_end'):
         node = nodes.Text(stream.current.value)
         stream.next()
         return node
     stream.expect('stroke_begin')
     children = parse_child_nodes(stream, self, 'strike_end')
     stream.expect('stroke_end')
     return nodes.Stroke(children)
Ejemplo n.º 6
0
 def parse(self, stream):
     if stream.test("stroke_end"):
         node = nodes.Text(stream.current.value)
         stream.next()
         return node
     stream.expect("stroke_begin")
     children = parse_child_nodes(stream, self, "strike_end")
     stream.expect("stroke_end")
     return nodes.Stroke(children)
Ejemplo n.º 7
0
    def parse(self, stream):
        stream.expect('quote_begin')
        user = stream.expect('quote_user')
        ret = []

        if user.value is not None:
            u = user.value
            user = u[-1] == ':' and u or u'%s said:' % u
            ret = [nodes.Strong([nodes.Text(user)]), nodes.Newline()]

        children = parse_child_nodes(stream, self, 'quote_end')
        stream.expect('quote_end')
        return nodes.Container(ret + [nodes.Quote(children)])
Ejemplo n.º 8
0
    def parse(self, stream):
        stream.expect('quote_begin')
        user = stream.expect('quote_user')
        ret = []

        if user.value is not None:
            u = user.value
            user = u[-1] == ':' and u or u'%s said:' % u
            ret = [nodes.Strong([nodes.Text(user)]), nodes.Newline()]

        children = parse_child_nodes(stream, self, 'quote_end')
        stream.expect('quote_end')
        return nodes.Container(ret + [nodes.Quote(children)])
Ejemplo n.º 9
0
    def parse(self, stream):
        if stream.test('list_item'):
            # parse list items
            stream.next()
            val = self.machine.dispatch_node(stream)
            return nodes.ListItem([nodes.Text(val)])

        def finish():
            return nodes.List(list_type, children)

        def is_empty_node(node):
            return node.is_linebreak_node or \
                   (node.is_text_node and not node.text.strip())

        def finish_if_list_end():
            if stream.test('list_end'):
                stream.next()
                return finish()

        stream.expect('list_begin')
        t = stream.expect('list_type')
        if not t.value:
            list_type = 'unordered'
        else:
            list_type = {
                '1':    'arabic',
                'a':    'alphalower',
                'A':    'alphalower',
                '*':    'unordered'
            }.get(t.value, None)

        if list_type is None:
            ret = u'[list]' + (u''.join(filter_stream(
                               stream, ('list_end', 'eof'), False)))
            ret += stream.expect('list_end').value
            return nodes.Text(ret)

        children = filter(lambda n: not is_empty_node(n),
                          parse_child_nodes(stream, self, ('list_end', 'eof')))

        # broken markup, no end tags...
        if stream.eof:
            return finish()

        finish_if_list_end()

        return finish()
Ejemplo n.º 10
0
    def parse(self, stream):
        if stream.test('list_item'):
            # parse list items
            stream.next()
            val = self.machine.dispatch_node(stream)
            return nodes.ListItem([nodes.Text(val)])

        def finish():
            return nodes.List(list_type, children)

        def is_empty_node(node):
            return node.is_linebreak_node or \
                   (node.is_text_node and not node.text.strip())

        def finish_if_list_end():
            if stream.test('list_end'):
                stream.next()
                return finish()

        stream.expect('list_begin')
        t = stream.expect('list_type')
        if not t.value:
            list_type = 'unordered'
        else:
            list_type = {
                '1': 'arabic',
                'a': 'alphalower',
                'A': 'alphalower',
                '*': 'unordered'
            }.get(t.value, None)

        if list_type is None:
            ret = u'[list]' + (u''.join(
                filter_stream(stream, ('list_end', 'eof'), False)))
            ret += stream.expect('list_end').value
            return nodes.Text(ret)

        children = filter(lambda n: not is_empty_node(n),
                          parse_child_nodes(stream, self, ('list_end', 'eof')))

        # broken markup, no end tags...
        if stream.eof:
            return finish()

        finish_if_list_end()

        return finish()
Ejemplo n.º 11
0
 def parse(self, stream):
     stream.expect('big_begin')
     children = parse_child_nodes(stream, self, 'big_end')
     stream.expect('big_end')
     return nodes.Big(children)
Ejemplo n.º 12
0
 def parse(self, stream):
     stream.expect("sup_begin")
     children = parse_child_nodes(stream, self, "sup_end")
     stream.expect("sup_end")
     return nodes.Sup(children)
Ejemplo n.º 13
0
 def parse(self, stream):
     stream.expect('emphasized_begin')
     children = parse_child_nodes(stream, self, 'emphasized_end')
     stream.expect('emphasized_end')
     return nodes.Emphasized(children)
Ejemplo n.º 14
0
 def parse(self, stream):
     stream.expect("underline_begin")
     children = parse_child_nodes(stream, self, "underline_end")
     stream.expect("underline_end")
     return nodes.Underline(children)
Ejemplo n.º 15
0
 def parse(self, stream):
     stream.expect("emphasized_begin")
     children = parse_child_nodes(stream, self, "emphasized_end")
     stream.expect("emphasized_end")
     return nodes.Emphasized(children)
Ejemplo n.º 16
0
 def parse(self, stream):
     stream.expect("big_begin")
     children = parse_child_nodes(stream, self, "big_end")
     stream.expect("big_end")
     return nodes.Big(children)
Ejemplo n.º 17
0
 def parse(self, stream):
     stream.expect('sup_begin')
     children = parse_child_nodes(stream, self, 'sup_end')
     stream.expect('sup_end')
     return nodes.Sup(children)
Ejemplo n.º 18
0
 def parse(self, stream):
     stream.expect('color_begin')
     color = stream.expect('color').value
     children = parse_child_nodes(stream, self, 'color_end')
     stream.expect('color_end')
     return nodes.Color(color, children)
Ejemplo n.º 19
0
 def parse(self, stream):
     stream.expect('color_begin')
     color = stream.expect('color').value
     children = parse_child_nodes(stream, self, 'color_end')
     stream.expect('color_end')
     return nodes.Color(color, children)
Ejemplo n.º 20
0
 def parse(self, stream):
     stream.expect('underline_begin')
     children = parse_child_nodes(stream, self, 'underline_end')
     stream.expect('underline_end')
     return nodes.Underline(children)