Example #1
0
    def list_item_repl(self, _iter_content, stack, item, item_head, item_text):
        list_level = len(item_head)
        list_type = item_head[-1]

        # Try to locate the list element which matches the requested level and
        # type.
        while True:
            cur = stack.top()
            if cur.tag.name == 'body':
                break
            if cur.tag.name == 'list-item-body':
                if list_level > cur.list_level:
                    break
            if cur.tag.name == 'list':
                if list_level >= cur.list_level and list_type == cur.list_type:
                    break
            stack.pop()

        if cur.tag.name != 'list':
            generate = list_type == '#' and 'ordered' or 'unordered'
            attrib = {moin_page.item_label_generate: generate}
            element = moin_page.list(attrib=attrib)
            element.list_level, element.list_type = list_level, list_type
            stack.push(element)

        element = moin_page.list_item()
        element_body = moin_page.list_item_body()
        element_body.list_level, element_body.list_type = list_level, list_type

        stack.push(element)
        stack.push(element_body)

        self.parse_inline(item_text, stack)
Example #2
0
    def list_item_repl(self, _iter_content, stack, item, item_head, item_text):
        list_level = len(item_head)
        list_type = item_head[-1]

        # Try to locate the list element which matches the requested level and
        # type.
        while True:
            cur = stack.top()
            if cur.tag.name == "body":
                break
            if cur.tag.name == "list-item-body":
                if list_level > cur.list_level:
                    break
            if cur.tag.name == "list":
                if list_level >= cur.list_level and list_type == cur.list_type:
                    break
            stack.pop()

        if cur.tag.name != "list":
            generate = list_type == "#" and "ordered" or "unordered"
            attrib = {moin_page.item_label_generate: generate}
            element = moin_page.list(attrib=attrib)
            element.list_level, element.list_type = list_level, list_type
            stack.push(element)

        element = moin_page.list_item()
        element_body = moin_page.list_item_body()
        element_body.list_level, element_body.list_type = list_level, list_type

        stack.push(element)
        stack.push(element_body)

        self.parse_inline(item_text, stack)
Example #3
0
 def create_definition_list(self, items):
     """ creates an ET with a definition list made from items """
     def_list = moin_page.list()
     for label, body in items:
         item_label = moin_page.list_item_label(children=[label])
         item_body = moin_page.list_item_body(children=[body])
         item = moin_page.list_item(children=[item_label, item_body])
         def_list.append(item)
     return def_list
Example #4
0
 def create_definition_list(self, items):
     """ creates an ET with a definition list made from items """
     def_list = moin_page.list()
     for label, body in items:
         item_label = moin_page.list_item_label(children=[label])
         item_body = moin_page.list_item_body(children=[body])
         item = moin_page.list_item(children=[item_label, item_body])
         def_list.append(item)
     return def_list
Example #5
0
 def create_pagelink_list(self, pagenames, ordered=False):
     """ creates an ET with a list of pagelinks from a list of pagenames """
     page_list = moin_page.list(attrib={moin_page.item_label_generate: ordered and 'ordered' or 'unordered'})
     for pagename in pagenames:
         # This link can never reach pagelinks
         url = unicode(iri.Iri(scheme=u'wiki', authority=u'', path=u'/' + pagename))
         pagelink = moin_page.a(attrib={xlink.href: url}, children=[pagename])
         item_body = moin_page.list_item_body(children=[pagelink])
         item = moin_page.list_item(children=[item_body])
         page_list.append(item)
     return page_list
Example #6
0
 def create_pagelink_list(self, pagenames, ordered=False):
     """ creates an ET with a list of pagelinks from a list of pagenames """
     page_list = moin_page.list(attrib={moin_page.item_label_generate: ordered and 'ordered' or 'unordered'})
     for pagename in pagenames:
         # This link can never reach pagelinks
         url = unicode(iri.Iri(scheme=u'wiki', authority=u'', path=u'/' + pagename))
         pagelink = moin_page.a(attrib={xlink.href: url}, children=[pagename])
         item_body = moin_page.list_item_body(children=[pagelink])
         item = moin_page.list_item(children=[item_body])
         page_list.append(item)
     return page_list
Example #7
0
 def visit_enumerated_list(self, node):
     enum_style = {'arabic': None,
             'loweralpha': u'lower-alpha',
             'upperalpha': u'upper-alpha',
             'lowerroman': u'lower-roman',
             'upperroman': u'upper-roman'}
     new_node = moin_page.list(
             attrib={moin_page.item_label_generate: u'ordered'})
     type = enum_style.get(node['enumtype'], None)
     if type:
         new_node.set(moin_page.list_style_type, type)
     self.open_moin_page_node(new_node)
Example #8
0
 def visit_enumerated_list(self, node):
     enum_style = {
         'arabic': None,
         'loweralpha': u'lower-alpha',
         'upperalpha': u'upper-alpha',
         'lowerroman': u'lower-roman',
         'upperroman': u'upper-roman'
     }
     new_node = moin_page.list(
         attrib={moin_page.item_label_generate: u'ordered'})
     type = enum_style.get(node['enumtype'], None)
     if type:
         new_node.set(moin_page.list_style_type, type)
     self.open_moin_page_node(new_node)
Example #9
0
    def macro(self):
        iwlist = app.cfg.interwiki_map.items()
        iwlist.sort()

        iw_list = moin_page.list()
        for tag, url in iwlist:
            href = join_wiki(url, 'RecentChanges')
            link = moin_page.a(attrib={xlink.href: href}, children=[tag])
            label = moin_page.code(children=[link])
            iw_item_label = moin_page.list_item_label(children=[label])
            if '$PAGE' not in url:
                link = moin_page.a(attrib={xlink.href: url}, children=[url])
            else:
                link = url
            body = moin_page.code(children=[link])
            iw_item_body = moin_page.list_item_body(children=[body])
            iw_item = moin_page.list_item(children=[iw_item_label, iw_item_body])
            iw_list.append(iw_item)
        return iw_list
Example #10
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, iter_content=iter_content)
                # 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, iter_content=iter_content)
        else:
            new_stack = stack
            level = 0

        is_list = list_begin
        iter = _Iter(self.indent_iter(iter_content, text, level, is_list), startno=iter_content.lineno)
        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)
Example #11
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_alpha=None, list_roman=None, list_bullet=None,
                    list_start_number=None, list_start_roman=None, list_start_alpha=None,
                    list_none=None):

        level = len(indent)

        # default to blockquote / indented text / bulletless list
        list_type = 'unordered', 'no-bullet'

        if list_begin:
            if list_definition:
                list_type = 'definition', None
            elif list_numbers:
                list_type = 'ordered', None
            elif list_alpha and list_alpha[:2] == 'A.':
                list_type = 'ordered', 'upper-alpha'
            elif list_alpha:
                list_type = 'ordered', 'lower-alpha'
            elif list_roman and list_roman[:2] == 'I.':
                list_type = 'ordered', 'upper-roman'
            elif list_roman:
                list_type = 'ordered', 'lower-roman'
            elif list_bullet == u'*':
                list_type = 'unordered', 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 indent:
            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]
                if list_start_number or list_start_alpha or list_start_roman:
                    attrib[moin_page.list_start] = list_start_number or list_start_alpha or list_start_roman
                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_text:
                element_label = moin_page.list_item_label()
                stack.top_append(element_label)
                new_stack = _Stack(element_label, iter_content=iter_content)

                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, iter_content=iter_content)
        else:
            new_stack = stack

        iter = _Iter(self.indent_iter(iter_content, text, level), startno=iter_content.lineno)
        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 == 'nowiki':
                it = iter_content
            self._apply(match, 'block', it, new_stack)
Example #12
0
 def visit_definition_list(self, node):
     self.open_moin_page_node(moin_page.list())
Example #13
0
 def visit_block_quote(self, node):
     self.open_moin_page_node(moin_page.list())
     self.open_moin_page_node(moin_page.list_item())
     self.open_moin_page_node(moin_page.list_item_body())
Example #14
0
 def visit_definition_list(self, node):
     self.open_moin_page_node(moin_page.list())
Example #15
0
 def visit_bullet_list(self, node):
     self.open_moin_page_node(
         moin_page.list(
             attrib={moin_page.item_label_generate: u'unordered'}))
Example #16
0
 def visit_block_quote(self, node):
     self.open_moin_page_node(moin_page.list())
     self.open_moin_page_node(moin_page.list_item())
     self.open_moin_page_node(moin_page.list_item_body())
Example #17
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_alpha=None, list_roman=None, list_bullet=None,
                    list_start_number=None, list_start_roman=None, list_start_alpha=None,
                    list_none=None):

        level = len(indent)

        # default to blockquote / indented text / bulletless list
        list_type = 'unordered', 'no-bullet'

        if list_begin:
            if list_definition:
                list_type = 'definition', None
            elif list_numbers:
                list_type = 'ordered', None
            elif list_alpha and list_alpha[:2] == 'A.':
                list_type = 'ordered', 'upper-alpha'
            elif list_alpha:
                list_type = 'ordered', 'lower-alpha'
            elif list_roman and list_roman[:2] == 'I.':
                list_type = 'ordered', 'upper-roman'
            elif list_roman:
                list_type = 'ordered', 'lower-roman'
            elif list_bullet == u'*':
                list_type = 'unordered', 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 indent:
            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]
                if list_start_number or list_start_alpha or list_start_roman:
                    attrib[moin_page.list_start] = list_start_number or list_start_alpha or list_start_roman
                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_text:
                element_label = moin_page.list_item_label()
                stack.top_append(element_label)
                new_stack = _Stack(element_label, iter_content=iter_content)

                self.parse_inline(list_definition_text, new_stack, self.inline_re)
            if not list_definition_text or text:
                # if text == true, then we have object:: definition, not object::\n ::definition
                element_body = moin_page.list_item_body()
                element_body.level, element_body.type = level, type

                stack.push(element_body)
                new_stack = _Stack(element_body, iter_content=iter_content)
        else:
            new_stack = stack

        iter = _Iter(self.indent_iter(iter_content, text, level), startno=iter_content.lineno)
        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 == 'nowiki':
                it = iter_content
            self._apply(match, 'block', it, new_stack)
Example #18
0
 def visit_bullet_list(self, node):
     self.open_moin_page_node(moin_page.list(
         attrib={moin_page.item_label_generate: u'unordered'}))