当前位置: 首页>>代码示例>>Python>>正文


Python tree.moin_page函数代码示例

本文整理汇总了Python中MoinMoin.util.tree.moin_page函数的典型用法代码示例。如果您正苦于以下问题:Python moin_page函数的具体用法?Python moin_page怎么用?Python moin_page使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了moin_page函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: visit_qandaentry_number

    def visit_qandaentry_number(self, element, depth):
        """
        Convert::

            <question>Q</question><answer>A</answer>

        to::

            <list-item>
                <list-item-body><p>Q</p><p>A</p></list-item-body>
            </list-item>
        """
        items = []
        for child in element:
            if isinstance(child, ET.Element):
                if child.tag.name == 'question' or child.tag.name == 'answer':
                    r = self.visit(child, depth)
                    if r is None:
                        r = ()
                    elif not isinstance(r, (list, tuple)):
                        r = (r, )
                    items.extend(r)
            else:
                items.append(child)

        item_body = ET.Element(moin_page('list-item-body'), attrib={}, children=items)
        return ET.Element(moin_page('list-item'), attrib={}, children=[item_body])
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:27,代码来源:docbook_in.py

示例2: visit_simple_list

    def visit_simple_list(self, moin_page_tag, attrib, element, depth):
        """
        There is different list element in DocBook with different
        semantic meaning, but with an unique result in the DOM Tree.

        Here we handle the conversion of such of list.
        """
        list_item_tags = set(['listitem', 'step', 'stepalternatives', 'member'])
        items = []
        for child in element:
            if isinstance(child, ET.Element):
                if child.tag.name in list_item_tags:
                    children = self.visit(child, depth)
                    list_item_body = ET.Element(moin_page('list-item-body'), attrib={}, children=children)
                    tag = ET.Element(moin_page('list-item'), attrib={},
                                     children=[list_item_body])
                    tag = (tag, )
                    items.extend(tag)
                else:
                    r = self.visit(child, depth)
                    if r is None:
                        r = ()
                    elif not isinstance(r, (list, tuple)):
                        r = (r, )
                    items.extend(r)
            else:
                items.append(child)
        return ET.Element(moin_page.list, attrib=attrib, children=items)
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:28,代码来源:docbook_in.py

示例3: visit_list

    def visit_list(self, element):
        """
        Convert a list of item (whatever the type : ordered or unordered)
        So we have html code like::

            <ul>
                <li>Item 1</li>
                <li>Item 2</li>
            </ul>

        Which will be converted to::

            <list>
                <list-item>
                    <list-item-body>Item 1</list-item-body>
                </list-item>
                <list-item>
                    <list-item-body>Item 2</list-item-body>
                </list-item>
            </list>
        """
        # We will define the appropriate attribute
        # according to the type of the list
        attrib = {}
        if element.tag == "ul" or element.tag == "dir":
            attrib[moin_page('item-label-generate')] = 'unordered'
        elif element.tag == "ol":
            attrib[moin_page('item-label-generate')] = 'ordered'

        return ET.Element(moin_page.list, attrib=attrib, children=self.do_children(element))
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:30,代码来源:markdown_in.py

示例4: visit_docbook_seglistitem

    def visit_docbook_seglistitem(self, element, labels, depth):
        """
        A seglistitem is a list-item for a segmented list. It is quite
        special because it act list definition with label, but the labels
        are predetermined in the labels list.

        So we generate label/body couple according to the content in
        labels
        """
        new = []
        counter = 0
        for child in element:
            if isinstance(child, ET.Element):
                if child.tag.name == 'seg':
                    label_tag = ET.Element(moin_page('list-item-label'),
                                           attrib={}, children=labels[counter % len(labels)])
                    body_tag = ET.Element(moin_page('list-item-body'),
                                          attrib={}, children=self.visit(child, depth))
                    item_tag = ET.Element(moin_page('list-item'),
                                          attrib={}, children=[label_tag, body_tag])
                    item_tag = (item_tag, )
                    new.extend(item_tag)
                    counter += 1
                else:
                    r = self.visit(child, depth)
                    if r is None:
                        r = ()
                    elif not isinstance(r, (list, tuple)):
                        r = (r, )
                    new.extend(r)
            else:
                new.append(child)
        return new
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:33,代码来源:docbook_in.py

示例5: visit_moinpage_list

    def visit_moinpage_list(self, element):
        """
        Function called to handle the conversion of list.

        It will called a specific function to handle (un)ordered list,
        with the appropriate DocBook tag.

        Or a specific function to handle definition list.
        """
        item_label_generate = element.get(moin_page('item-label-generate'))
        if 'ordered' == item_label_generate:
            attrib = {}
            # Get the list-style-type to define correctly numeration
            list_style_type = element.get(moin_page('list-style-type'))
            if 'upper-alpha' == list_style_type:
                attrib[docbook('numeration')] = 'upperalpha'
            elif 'upper-roman' == list_style_type:
                attrib[docbook('numeration')] = 'upperroman'
            elif 'lower-alpha' == list_style_type:
                attrib[docbook('numeration')] = 'loweralpha'
            elif 'lower-roman' == list_style_type:
                attrib[docbook('numeration')] = 'lowerroman'
            else:
                attrib[docbook('numeration')] = 'arabic'

            return self.handle_simple_list(docbook.orderedlist,
                                           element, attrib=attrib)
        elif 'unordered' == item_label_generate:
            return self.handle_simple_list(docbook.itemizedlist,
                                           element, attrib={})
        else:
            return self.new_copy(docbook.variablelist, element, attrib={})
开发者ID:denedios,项目名称:moin-2.0,代码行数:32,代码来源:docbook_out.py

示例6: visit_data_element

    def visit_data_element(self, element, depth, object_data, text_object, caption):
        """
        We will try to return an object element based on the
        object_data. If it is not possible, we return a paragraph
        with the content of text_object.
        """
        attrib = {}
        preferred_format, data_tag, mimetype = self.media_tags[element.tag.name]
        if not object_data:
            if not text_object:
                return
            else:
                children = self.do_children(element, depth + 1)
                return self.new(moin_page.p, attrib={}, children=children)
        # We try to determine the best object to show
        for obj in object_data:
            format = obj.get('format')  # format is optional: <imagedata format="jpeg" fileref="jpeg.jpg"/>
            if format:
                format = format.lower()
                if format in preferred_format:
                    object_to_show = obj
                    break
                else:
                    # unsupported format
                    object_to_show = None
            else:
                # XXX: Maybe we could add some verification over the extension of the file
                object_to_show = obj

        if object_to_show is None:
            # we could not find any suitable object, return the text_object replacement.
            children = self.do_children(text_object, depth + 1)
            return self.new(moin_page.p, attrib={}, children=children)

        href = object_to_show.get('fileref')
        if not href:
            # We could probably try to use entityref,
            # but at this time we won't support it.
            return
        attrib[html.alt] = href
        attrib[xlink.href] = '+get/' + href
        format = object_to_show.get('format')
        if format:
            format = format.lower()
            attrib[moin_page('type')] = ''.join([mimetype, format])
        else:
            attrib[moin_page('type')] = mimetype
        align = object_to_show.get('align')
        if align and align in set(['left', 'center', 'right', 'top', 'middle', 'bottom']):
            attrib[html.class_] = align

        # return object tag, html_out.py will convert to img, audio, or video based on type attr
        ret = ET.Element(moin_page.object, attrib=attrib)
        ret = mark_item_as_transclusion(ret, href)
        if caption:
            caption = self.new(moin_page.span, attrib={moin_page.class_: 'db-caption'}, children=[caption])
            return self.new(moin_page.span, attrib={}, children=[ret, caption])
        else:
            return ret
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:59,代码来源:docbook_in.py

示例7: add_attr_to_style

 def add_attr_to_style(attrib, attr):
     attr = attr.strip().decode('unicode-escape')
     if not attr.endswith(';'):
         attr += ';'
     if attrib.get(moin_page('style'), ""):
         attrib[moin_page('style')] = attrib.get(moin_page('style'), "") + " " + attr
     else:
         attrib[moin_page('style')] = attr
开发者ID:rciorba,项目名称:moin-2.0-mirror,代码行数:8,代码来源:moinwiki_in.py

示例8: error

 def error(self, message):
     """
     Return a DOM Tree containing an error message.
     """
     error = self.new(moin_page('error'), attrib={}, children=[message])
     part = self.new(moin_page('part'), attrib={}, children=[error])
     body = self.new(moin_page('body'), attrib={}, children=[part])
     return self.new(moin_page('page'), attrib={}, children=[body])
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:8,代码来源:docbook_in.py

示例9: visit_docbook_footnote

 def visit_docbook_footnote(self, element, depth):
     """
     <footnote> --> <note note-class="footnote"><note-body>
     """
     attrib = {}
     key = moin_page("note-class")
     attrib[key] = "footnote"
     children = self.new(moin_page("note-body"), attrib={}, children=self.do_children(element, depth))
     return self.new(moin_page.note, attrib=attrib, children=[children])
开发者ID:rciorba,项目名称:moin-2.0-mirror,代码行数:9,代码来源:docbook_in.py

示例10: visit_xhtml_td

 def visit_xhtml_td(self, element):
     attrib = {}
     rowspan = element.get(html.rowspan)
     colspan = element.get(html.colspan)
     if rowspan:
         attrib[moin_page('number-rows-spanned')] = rowspan
     if colspan:
         attrib[moin_page('number-columns-spanned')] = colspan
     return self.new_copy(moin_page.table_cell, element, attrib=attrib)
开发者ID:rciorba,项目名称:moin-2.0-mirror,代码行数:9,代码来源:html_in.py

示例11: visit_moinpage_table_cell

 def visit_moinpage_table_cell(self, element):
     attrib = {}
     rowspan = element.get(moin_page('number-rows-spanned'))
     colspan = element.get(moin_page('number-columns-spanned'))
     print "rowspan : {0}".format(rowspan)
     if rowspan:
         attrib[docbook.rowspan] = rowspan
     if colspan:
         attrib[docbook.colspan] = colspan
     return self.new_copy(docbook.td, element, attrib=attrib)
开发者ID:denedios,项目名称:moin-2.0,代码行数:10,代码来源:docbook_out.py

示例12: block_table_repl

    def block_table_repl(self, iter_content, stack, table, table_args=''):
        stack.clear()
        # TODO: table attributes
        elem = moin_page.table()
        stack.push(elem)
        if table_args:
            table_args = _TableArguments()(table_args)
            for key, value in table_args.keyword.iteritems():
                attrib = elem.attrib
                if key in ('class', 'style', 'number-columns-spanned', 'number-rows-spanned'):
                    attrib[moin_page(key)] = value

        element = moin_page.table_body()
        stack.push(element)
        lines = _Iter(self.block_table_lines(iter_content), startno=iter_content.lineno)
        element = moin_page.table_row()
        stack.push(element)
        preprocessor_status = []
        for line in lines:
            m = self.tablerow_re.match(line)
            if not m:
                return
            if m.group('newrow'):
                stack.pop_name('table-row')
                element = moin_page.table_row()
                stack.push(element)
            cells = m.group('cells')
            if cells:
                cells = cells.split('||')
                for cell in cells:
                    if stack.top_check('table-cell'):
                        stack.pop()

                    cell = re.split(r'\s*\|\s*', cell)
                    element = moin_page.table_cell()
                    if len(cell) > 1:
                        cell_args = _TableArguments()(cell[0])
                        for key, value in cell_args.keyword.iteritems():
                            attrib = element.attrib
                            if key in ('class', 'style', 'number-columns-spanned', 'number-rows-spanned'):
                                attrib[moin_page(key)] = value
                        cell = cell[1]
                    else:
                        cell = cell[0]
                    stack.push(element)
                    self.preprocessor.push()
                    self.parse_inline(cell, stack, self.inline_re)
                    preprocessor_status = self.preprocessor.pop()
            elif m.group('text'):
                self.preprocessor.push(preprocessor_status)
                self.parse_inline('\n{0}'.format(m.group('text')), stack, self.inline_re)
                preprocessor_status = self.preprocessor.pop()
        stack.pop_name('table')
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:53,代码来源:mediawiki_in.py

示例13: visit_docbook_td

 def visit_docbook_td(self, element, depth):
     """
     <td> --> <table-cell>
     """
     attrib = {}
     rowspan = element.get("rowspan")
     colspan = element.get("colspan")
     if rowspan:
         attrib[moin_page("number-rows-spanned")] = rowspan
     if colspan:
         attrib[moin_page("number-columns-spanned")] = colspan
     return self.new_copy(moin_page.table_cell, element, depth, attrib=attrib)
开发者ID:rciorba,项目名称:moin-2.0-mirror,代码行数:12,代码来源:docbook_in.py

示例14: block_table_repl

    def block_table_repl(self, iter_content, stack, table, table_args=""):
        stack.clear()
        # TODO: table attributes
        elem = moin_page.table()
        stack.push(elem)
        if table_args:
            table_args = _TableArguments()(table_args)
            for key, value in table_args.keyword.iteritems():
                attrib = elem.attrib
                if key in ("class", "style", "number-columns-spanned", "number-rows-spanned"):
                    attrib[moin_page(key)] = value

        element = moin_page.table_body()
        stack.push(element)
        lines = _Iter(self.block_table_lines(iter_content))
        element = moin_page.table_row()
        stack.push(element)
        preprocessor_status = []
        for line in lines:
            m = self.tablerow_re.match(line)
            if not m:
                return
            if m.group("newrow"):
                stack.pop_name("table-row")
                element = moin_page.table_row()
                stack.push(element)
            cells = m.group("cells")
            if cells:
                cells = cells.split("||")
                for cell in cells:
                    if stack.top_check("table-cell"):
                        stack.pop()

                    cell = re.split(r"\s*\|\s*", cell)
                    element = moin_page.table_cell()
                    if len(cell) > 1:
                        cell_args = _TableArguments()(cell[0])
                        for key, value in cell_args.keyword.iteritems():
                            attrib = element.attrib
                            if key in ("class", "style", "number-columns-spanned", "number-rows-spanned"):
                                attrib[moin_page(key)] = value
                        cell = cell[1]
                    else:
                        cell = cell[0]
                    stack.push(element)
                    self.preprocessor.push()
                    self.parse_inline(cell, stack, self.inline_re)
                    preprocessor_status = self.preprocessor.pop()
            elif m.group("text"):
                self.preprocessor.push(preprocessor_status)
                self.parse_inline("\n{0}".format(m.group("text")), stack, self.inline_re)
                preprocessor_status = self.preprocessor.pop()
        stack.pop_name("table")
开发者ID:pombredanne,项目名称:moin2,代码行数:53,代码来源:mediawiki_in.py

示例15: visit_docbook_footnote

 def visit_docbook_footnote(self, element, depth):
     """
     <footnote> --> <note note-class="footnote"><note-body>
     """
     attrib = {}
     key = moin_page('note-class')
     attrib[key] = "footnote"
     children = self.new(moin_page('note-body'), attrib={},
                         children=self.do_children(element, depth))
     if len(children) > 1:
         # must delete lineno because footnote will be placed near end of page and out of sequence
         del children._children[1].attrib[html.data_lineno]
     return self.new(moin_page.note, attrib=attrib, children=[children])
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:13,代码来源:docbook_in.py


注:本文中的MoinMoin.util.tree.moin_page函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。