• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python tree.moin_page函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: visit_docbook_trademark

    def visit_docbook_trademark(self, element, depth):
        """
        Depending of the trademark class, a specific entities is added to the string.

        Docbook supports 4 types of trademark: copyright, registered, trade (mark), and service (mark).
        <trademark> --> <span class="db-trademark">
        """
        trademark_entities = {'copyright': u'\u00a9 ',
                              'registered': u'\u00ae',
                              'trade': u'\u2122',
        }
        trademark_class = element.get('class')
        children = self.do_children(element, depth)
        if trademark_class in trademark_entities:
            if trademark_class == 'copyright':
                children.insert(0, trademark_entities[trademark_class])
            else:
                children.append(trademark_entities[trademark_class])
        elif trademark_class == 'service':
            sup_attrib = {moin_page('baseline-shift'): 'super'}
            service_mark = self.new(moin_page.span, attrib=sup_attrib,
                                    children=['SM'])
            children.append(service_mark)
        attrib = {html.class_: 'db-trademark'}
        return self.new(moin_page.span, attrib=attrib, children=children)
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:25,代码来源:docbook_in.py


示例17: visit_docbook_sect

    def visit_docbook_sect(self, element, depth):
        """
        This is the function to convert a numbered section.

        Numbered section uses tag like <sectN> where N is the number
        of the section between 1 and 5.

        The sections are supposed to be correctly nested.

        We only convert a section to an heading if one of the children
        is a title element.

        TODO: See if we can unify with recursive section below.
        TODO: Add div element, with specific id
        """
        self.is_section = True
        title = ''
        for child in element:
            if isinstance(child, ET.Element):
                uri = child.tag.uri
                name = self.docbook_namespace.get(uri, None)
                if name == 'docbook' and child.tag.name == 'title':
                    title = child
                    # Remove the title element to avoid double conversion
                    element.remove(child)
        heading_level = element.tag.name[4]
        key = moin_page('outline-level')
        attrib = {}
        attrib[key] = heading_level
        return self.new(moin_page.h, attrib=attrib, children=title)
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:30,代码来源:docbook_in.py


示例18: visit_docbook_blockquote

    def visit_docbook_blockquote(self, element, depth):
        """
        <blockquote>
          <attribution>Author</attribution>
          Text
        </blockquote>
          --> <blockquote source="Author">Text</blockquote>

        <blockquote>Text</blockquote>
          --> <blockquote source="Unknow">Text</blockquote>
        """
        # TODO: Translate
        source = u"Unknow"
        children = []
        for child in element:
            if isinstance(child, ET.Element):
                if child.tag.name == "attribution":
                    source = self.do_children(child, depth + 1)
                else:
                    children.extend(self.do_children(child, depth + 1))
            else:
                children.append(child)
        attrib = {}
        attrib[moin_page('source')] = source[0]
        return self.new(moin_page.blockquote, attrib=attrib, children=children)
开发者ID:YelaSeamless,项目名称:moin-2.0,代码行数:25,代码来源:docbook_in.py


示例19: visit_docbook_informalfigure

 def visit_docbook_informalfigure(self, element, depth):
     """
     <informalfigure> --> <div html:class="figure">
     """
     attrib = {}
     attrib[html("class")] = "db-figure"
     return self.new_copy(moin_page("div"), element, depth, attrib=attrib)
开发者ID:rciorba,项目名称:moin-2.0-mirror,代码行数:7,代码来源:docbook_in.py


示例20: build_dom_table

 def build_dom_table(self, rows, head=None, cls=None):
     """
     Build a DOM table with data from <rows>.
     """
     table = moin_page.table()
     if cls is not None:
         table.attrib[moin_page('class')] = cls
     if head is not None:
         table_head = moin_page.table_header()
         table_row = moin_page.table_row()
         for idx, cell in enumerate(head):
             table_cell = moin_page.table_cell(children=[cell, ],)
             if rows:
                 # add "align: right" to heading cell if cell in first data row is numeric
                 self.add_numeric_class(rows[0][idx], table_cell)
             table_row.append(table_cell)
         table_head.append(table_row)
         table.append(table_head)
     table_body = moin_page.table_body()
     for row in rows:
         table_row = moin_page.table_row()
         for cell in row:
             if isinstance(cell, ET.Node) and isinstance(cell[0], unicode) and \
                 len(cell[0].split()) == 1 and len(cell[0]) > WORDBREAK_LEN:
                 # avoid destroying table layout by applying special styling to cells with long file name hyperlinks
                 table_cell = moin_page.table_cell(children=[cell, ], attrib={moin_page.class_: 'moin-wordbreak'})
             else:
                 table_cell = moin_page.table_cell(children=[cell, ],)
                 self.add_numeric_class(cell, table_cell)
             table_row.append(table_cell)
         table_body.append(table_row)
     table.append(table_body)
     return table
开发者ID:gitpraetorianlabs,项目名称:moin-2.0,代码行数:33,代码来源:_table.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python wikiutil.escape函数代码示例发布时间:2022-05-24
下一篇:
Python pysupport.getPackageModules函数代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap