示例#1
0
    def parse_block(self, iter_content, arguments):
        attrib = {}
        if arguments:
            for key, value in arguments.keyword.iteritems():
                if key in ("style",):
                    attrib[moin_page(key)] = value
                elif key == "_old":
                    attrib[moin_page.class_] = value.replace("/", " ")

        body = moin_page.body(attrib=attrib)

        stack = _Stack(body)

        for line in iter_content:
            match = self.indent_re.match(line)
            if match:
                data = dict(((str(k), v) for k, v in match.groupdict().iteritems() if v is not None))
                self.indent_repl(iter_content, stack, line, **data)
            else:
                self.indent_repl(iter_content, stack, line, "", line)

        return body
    def parse_block(self, iter_content, arguments):
        attrib = {}
        if arguments:
            for key, value in arguments.keyword.iteritems():
                if key in ('style', ):
                    attrib[moin_page(key)] = value
                elif key == '_old':
                    attrib[moin_page.class_] = value.replace('/', ' ')

        body = moin_page.body(attrib=attrib)

        stack = _Stack(body)

        for line in iter_content:
            match = self.indent_re.match(line)
            if match:
                data = dict(((str(k), v)
                             for k, v in match.groupdict().iteritems()
                             if v is not None))
                self.indent_repl(iter_content, stack, line, **data)
            else:
                self.indent_repl(iter_content, stack, line, '', line)

        return body
    def indent_repl(self,
                    iter_content,
                    stack,
                    line,
                    indent,
                    text,
                    list_begin=None,
                    list_definition=None,
                    list_definition_text=None,
                    list_numbers=None,
                    list_bullet=None,
                    list_none=None):

        level = len(indent)
        list_type = 'unordered', 'none'
        if list_begin:
            if list_definition:
                list_type = 'definition', None
            elif list_numbers:
                list_type = 'ordered', None
            elif list_bullet:
                list_type = 'unordered', None
            elif list_none:
                list_type = None, None

        element_use = None
        while len(stack) > 1:
            cur = stack.top()
            if cur.tag.name == 'list-item-body':
                if level > cur.level:
                    element_use = cur
                    break
            if cur.tag.name == 'list':
                if level >= cur.level and list_type == cur.list_type:
                    element_use = cur
                    break
            stack.pop()

        if not element_use:
            element_use = stack.top()
        if list_begin:
            if element_use.tag.name != 'list':
                attrib = {}
                if not list_definition:
                    attrib[moin_page.item_label_generate] = list_type[0]
                if list_type[1]:
                    attrib[moin_page.list_style_type] = list_type[1]
                element = moin_page.list(attrib=attrib)
                element.level, element.list_type = level, list_type
                stack.push(element)

            stack.push(moin_page.list_item())
            if list_definition:
                element_label = moin_page.list_item_label()
                stack.top_append(element_label)
                new_stack = _Stack(element_label)
                # TODO: definition list doesn't work,
                #       if definition of the term on the next line
                splited_text = text.split(':')
                list_definition_text = splited_text.pop(0)
                text = ':'.join(splited_text)

                self.parse_inline(list_definition_text, new_stack,
                                  self.inline_re)

            element_body = moin_page.list_item_body()
            element_body.level, element_body.type = level, type

            stack.push(element_body)
            new_stack = _Stack(element_body)
        else:
            new_stack = stack
            level = 0

        is_list = list_begin
        iter = _Iter(self.indent_iter(iter_content, text, level, is_list))
        for line in iter:
            match = self.block_re.match(line)
            it = iter
            # XXX: Hack to allow nowiki to ignore the list identation
            if match.lastgroup == 'table' or match.lastgroup == 'nowiki':
                it = iter_content
            self._apply(match, 'block', it, new_stack)
示例#4
0
    def indent_repl(
        self,
        iter_content,
        stack,
        line,
        indent,
        text,
        list_begin=None,
        list_definition=None,
        list_definition_text=None,
        list_numbers=None,
        list_bullet=None,
        list_none=None,
    ):

        level = len(indent)
        list_type = "unordered", "none"
        if list_begin:
            if list_definition:
                list_type = "definition", None
            elif list_numbers:
                list_type = "ordered", None
            elif list_bullet:
                list_type = "unordered", None
            elif list_none:
                list_type = None, None

        element_use = None
        while len(stack) > 1:
            cur = stack.top()
            if cur.tag.name == "list-item-body":
                if level > cur.level:
                    element_use = cur
                    break
            if cur.tag.name == "list":
                if level >= cur.level and list_type == cur.list_type:
                    element_use = cur
                    break
            stack.pop()

        if not element_use:
            element_use = stack.top()
        if list_begin:
            if element_use.tag.name != "list":
                attrib = {}
                if not list_definition:
                    attrib[moin_page.item_label_generate] = list_type[0]
                if list_type[1]:
                    attrib[moin_page.list_style_type] = list_type[1]
                element = moin_page.list(attrib=attrib)
                element.level, element.list_type = level, list_type
                stack.push(element)

            stack.push(moin_page.list_item())
            if list_definition:
                element_label = moin_page.list_item_label()
                stack.top_append(element_label)
                new_stack = _Stack(element_label)
                # TODO: definition list doesn't work,
                #       if definition of the term on the next line
                splited_text = text.split(":")
                list_definition_text = splited_text.pop(0)
                text = ":".join(splited_text)

                self.parse_inline(list_definition_text, new_stack, self.inline_re)

            element_body = moin_page.list_item_body()
            element_body.level, element_body.type = level, type

            stack.push(element_body)
            new_stack = _Stack(element_body)
        else:
            new_stack = stack
            level = 0

        is_list = list_begin
        iter = _Iter(self.indent_iter(iter_content, text, level, is_list))
        for line in iter:
            match = self.block_re.match(line)
            it = iter
            # XXX: Hack to allow nowiki to ignore the list identation
            if match.lastgroup == "table" or match.lastgroup == "nowiki":
                it = iter_content
            self._apply(match, "block", it, new_stack)