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


Python nodes.clean_astext函数代码示例

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


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

示例1: process_doc

 def process_doc(self, env, docname, document):
     labels, anonlabels = self.data["labels"], self.data["anonlabels"]
     for name, explicit in iteritems(document.nametypes):
         if not explicit:
             continue
         labelid = document.nameids[name]
         if labelid is None:
             continue
         node = document.ids[labelid]
         if name.isdigit() or "refuri" in node or node.tagname.startswith("desc_"):
             # ignore footnote labels, labels automatically generated from a
             # link and object descriptions
             continue
         if name in labels:
             env.warn_node(
                 "duplicate label %s, " % name + "other instance " "in " + env.doc2path(labels[name][0]), node
             )
         anonlabels[name] = docname, labelid
         if node.tagname == "section":
             sectname = clean_astext(node[0])  # node[0] == title node
         elif node.tagname == "figure":
             for n in node:
                 if n.tagname == "caption":
                     sectname = clean_astext(n)
                     break
             else:
                 continue
         elif node.tagname == "image" and node.parent.tagname == "figure":
             for n in node.parent:
                 if n.tagname == "caption":
                     sectname = clean_astext(n)
                     break
             else:
                 continue
         elif node.tagname == "table":
             for n in node:
                 if n.tagname == "title":
                     sectname = clean_astext(n)
                     break
             else:
                 continue
         elif node.tagname == "container" and node.get("literal_block"):
             for n in node:
                 if n.tagname == "caption":
                     sectname = clean_astext(n)
                     break
             else:
                 continue
         elif node.traverse(addnodes.toctree):
             n = node.traverse(addnodes.toctree)[0]
             if n.get("caption"):
                 sectname = n["caption"]
             else:
                 continue
         else:
             # anonymous-only labels
             continue
         labels[name] = docname, labelid, sectname
开发者ID:martin-zheng,项目名称:sphinx,代码行数:58,代码来源:std.py

示例2: process_doc

 def process_doc(self, env, docname, document):
     labels, anonlabels = self.data['labels'], self.data['anonlabels']
     for name, explicit in iteritems(document.nametypes):
         if not explicit:
             continue
         labelid = document.nameids[name]
         if labelid is None:
             continue
         node = document.ids[labelid]
         if name.isdigit() or 'refuri' in node or \
            node.tagname.startswith('desc_'):
             # ignore footnote labels, labels automatically generated from a
             # link and object descriptions
             continue
         if name in labels:
             env.warn_node('duplicate label %s, ' % name + 'other instance '
                           'in ' + env.doc2path(labels[name][0]), node)
         anonlabels[name] = docname, labelid
         if node.tagname == 'section':
             sectname = clean_astext(node[0])  # node[0] == title node
         elif node.tagname == 'figure':
             for n in node:
                 if n.tagname == 'caption':
                     sectname = clean_astext(n)
                     break
             else:
                 continue
         elif node.tagname == 'image' and node.parent.tagname == 'figure':
             for n in node.parent:
                 if n.tagname == 'caption':
                     sectname = clean_astext(n)
                     break
             else:
                 continue
         elif node.tagname == 'table':
             for n in node:
                 if n.tagname == 'title':
                     sectname = clean_astext(n)
                     break
             else:
                 continue
         elif node.tagname == 'container' and node.get('literal_block'):
             for n in node:
                 if n.tagname == 'caption':
                     sectname = clean_astext(n)
                     break
             else:
                 continue
         elif node.traverse(addnodes.toctree):
             n = node.traverse(addnodes.toctree)[0]
             if n.get('caption'):
                 sectname = n['caption']
             else:
                 continue
         else:
             # anonymous-only labels
             continue
         labels[name] = docname, labelid, sectname
开发者ID:861008761,项目名称:standard_flask_web,代码行数:58,代码来源:std.py

示例3: test_clean_astext

def test_clean_astext():
    node = nodes.paragraph(text='hello world')
    assert 'hello world' == clean_astext(node)

    node = nodes.image(alt='hello world')
    assert '' == clean_astext(node)

    node = nodes.paragraph(text='hello world')
    node += nodes.raw('', 'raw text', format='html')
    assert 'hello world' == clean_astext(node)
开发者ID:Felix-neko,项目名称:sphinx,代码行数:10,代码来源:test_util_nodes.py

示例4: add_kernel_figure_to_std_domain

def add_kernel_figure_to_std_domain(app, doctree):
    """Add kernel-figure anchors to 'std' domain.

    The ``StandardDomain.process_doc(..)`` method does not know how to resolve
    the caption (label) of ``kernel-figure`` directive (it only knows about
    standard nodes, e.g. table, figure etc.). Without any additional handling
    this will result in a 'undefined label' for kernel-figures.

    This handle adds labels of kernel-figure to the 'std' domain labels.
    """

    std = app.env.domains["std"]
    docname = app.env.docname
    labels = std.data["labels"]

    for name, explicit in iteritems(doctree.nametypes):
        if not explicit:
            continue
        labelid = doctree.nameids[name]
        if labelid is None:
            continue
        node = doctree.ids[labelid]

        if node.tagname == 'kernel_figure':
            for n in node.next_node():
                if n.tagname == 'caption':
                    sectname = clean_astext(n)
                    # add label to std domain
                    labels[name] = docname, labelid, sectname
                    break
开发者ID:0x7f454c46,项目名称:linux,代码行数:30,代码来源:kfigure.py

示例5: get_numfig_title

    def get_numfig_title(self, node):
        """Get the title of enumerable nodes to refer them using its title"""
        if self.is_enumerable_node(node):
            _, title_getter = self.enumerable_nodes.get(node.__class__, (None, None))
            if title_getter:
                return title_getter(node)
            else:
                for subnode in node:
                    if subnode.tagname in ('caption', 'title'):
                        return clean_astext(subnode)

        return None
开发者ID:avirshup,项目名称:sphinx,代码行数:12,代码来源:std.py

示例6: process_doc

 def process_doc(self, env, docname, document):
     labels, anonlabels = self.data['labels'], self.data['anonlabels']
     for name, explicit in document.nametypes.iteritems():
         if not explicit:
             continue
         labelid = document.nameids[name]
         if labelid is None:
             continue
         node = document.ids[labelid]
         if name.isdigit() or node.has_key('refuri') or \
                node.tagname.startswith('desc_'):
             # ignore footnote labels, labels automatically generated from a
             # link and object descriptions
             continue
         if name in labels:
             env.warn(docname, 'duplicate label %s, ' % name +
                      'other instance in ' + env.doc2path(labels[name][0]),
                      node.line)
         anonlabels[name] = docname, labelid
         if node.tagname == 'section':
             sectname = clean_astext(node[0]) # node[0] == title node
         elif node.tagname == 'figure':
             for n in node:
                 if n.tagname == 'caption':
                     sectname = clean_astext(n)
                     break
             else:
                 continue
         elif node.tagname == 'table':
             for n in node:
                 if n.tagname == 'title':
                     sectname = clean_astext(n)
                     break
             else:
                 continue
         else:
             # anonymous-only labels
             continue
         labels[name] = docname, labelid, sectname
开发者ID:ZoomQuiet,项目名称:python-doc-translation,代码行数:39,代码来源:std.py

示例7: doctree_read

def doctree_read(app, doctree):
    """
    为了sec-开头标签能正常工作需要将其添加进:
    env.domains["std"].data["labels"]
    sec-test: 文章名, 标签名, 章节名,
    """
    labels = app.env.domains["std"].data["labels"]
    for name, _ in doctree.nametypes.iteritems():
        if not name.startswith("sec-"): continue
        labelid = doctree.nameids[name]
        node = doctree.ids[labelid].parent
        if node.tagname == 'section':
            sectname = clean_astext(node[0])
            labels[name] = app.env.docname, labelid, sectname
开发者ID:Mondego,项目名称:pyreco,代码行数:14,代码来源:allPythonContent.py

示例8: register_sections_as_label

def register_sections_as_label(app, document):
    labels = app.env.domaindata['std']['labels']
    anonlabels = app.env.domaindata['std']['anonlabels']
    for node in document.traverse(nodes.section):
        name = nodes.fully_normalize_name(node[0].astext())
        labelid = node['ids'][0]
        docname = app.env.docname
        sectname = clean_astext(node[0])

        if name in labels:
            app.env.warn_node('duplicate label %s, ' % name + 'other instance '
                              'in ' + app.env.doc2path(labels[name][0]), node)

        anonlabels[name] = docname, labelid
        labels[name] = docname, labelid, sectname
开发者ID:AlexEshoo,项目名称:sphinx,代码行数:15,代码来源:autosectionlabel.py

示例9: get_objects

 def get_objects(self):
     # handle the special 'doc' reference here
     for doc in self.env.all_docs:
         yield (doc, clean_astext(self.env.titles[doc]), "doc", doc, "", -1)
     for (prog, option), info in iteritems(self.data["progoptions"]):
         yield (option, option, "option", info[0], info[1], 1)
     for (type, name), info in iteritems(self.data["objects"]):
         yield (name, name, type, info[0], info[1], self.object_types[type].attrs["searchprio"])
     for name, info in iteritems(self.data["labels"]):
         yield (name, info[2], "label", info[0], info[1], -1)
     # add anonymous-only labels as well
     non_anon_labels = set(self.data["labels"])
     for name, info in iteritems(self.data["anonlabels"]):
         if name not in non_anon_labels:
             yield (name, name, "label", info[0], info[1], -1)
开发者ID:martin-zheng,项目名称:sphinx,代码行数:15,代码来源:std.py

示例10: _resolve_doc_xref

 def _resolve_doc_xref(self, env, fromdocname, builder, typ, target, node, contnode):
     # type: (BuildEnvironment, str, Builder, str, str, addnodes.pending_xref, nodes.Element) -> nodes.Element  # NOQA
     # directly reference to document by source name; can be absolute or relative
     refdoc = node.get('refdoc', fromdocname)
     docname = docname_join(refdoc, node['reftarget'])
     if docname not in env.all_docs:
         return None
     else:
         if node['refexplicit']:
             # reference with explicit title
             caption = node.astext()
         else:
             caption = clean_astext(env.titles[docname])
         innernode = nodes.inline(caption, caption, classes=['doc'])
         return make_refnode(builder, fromdocname, docname, None, innernode)
开发者ID:olivier-heurtier,项目名称:sphinx,代码行数:15,代码来源:std.py

示例11: get_objects

 def get_objects(self):
     # handle the special 'doc' reference here
     for doc in self.env.all_docs:
         yield (doc, clean_astext(self.env.titles[doc]), 'doc', doc, '', -1)
     for (prog, option), info in iteritems(self.data['progoptions']):
         yield (option, option, 'option', info[0], info[1], 1)
     for (type, name), info in iteritems(self.data['objects']):
         yield (name, name, type, info[0], info[1],
                self.object_types[type].attrs['searchprio'])
     for name, info in iteritems(self.data['labels']):
         yield (name, info[2], 'label', info[0], info[1], -1)
     # add anonymous-only labels as well
     non_anon_labels = set(self.data['labels'])
     for name, info in iteritems(self.data['anonlabels']):
         if name not in non_anon_labels:
             yield (name, name, 'label', info[0], info[1], -1)
开发者ID:avirshup,项目名称:sphinx,代码行数:16,代码来源:std.py

示例12: _resolve_doc_reference

 def _resolve_doc_reference(self, builder, refdoc, node, contnode):
     # directly reference to document by source name;
     # can be absolute or relative
     docname = docname_join(refdoc, node['reftarget'])
     if docname in self.all_docs:
         if node['refexplicit']:
             # reference with explicit title
             caption = node.astext()
         else:
             caption = clean_astext(self.titles[docname])
         innernode = nodes.inline(caption, caption)
         innernode['classes'].append('doc')
         newnode = nodes.reference('', '', internal=True)
         newnode['refuri'] = builder.get_relative_uri(refdoc, docname)
         newnode.append(innernode)
         return newnode
开发者ID:techtonik,项目名称:sphinx,代码行数:16,代码来源:__init__.py

示例13: note_labels

 def note_labels(self, env, docname, document):
     # type: (BuildEnvironment, str, nodes.document) -> None
     labels, anonlabels = self.data['labels'], self.data['anonlabels']
     for name, explicit in document.nametypes.items():
         if not explicit:
             continue
         labelid = document.nameids[name]
         if labelid is None:
             continue
         node = document.ids[labelid]
         if isinstance(node, nodes.target) and 'refid' in node:
             # indirect hyperlink targets
             node = document.ids.get(node['refid'])
             labelid = node['names'][0]
         if (node.tagname == 'footnote' or
                 'refuri' in node or
                 node.tagname.startswith('desc_')):
             # ignore footnote labels, labels automatically generated from a
             # link and object descriptions
             continue
         if name in labels:
             logger.warning(__('duplicate label %s, other instance in %s'),
                            name, env.doc2path(labels[name][0]),
                            location=node)
         anonlabels[name] = docname, labelid
         if node.tagname in ('section', 'rubric'):
             title = cast(nodes.title, node[0])
             sectname = clean_astext(title)
         elif self.is_enumerable_node(node):
             sectname = self.get_numfig_title(node)
             if not sectname:
                 continue
         elif node.traverse(addnodes.toctree):
             n = node.traverse(addnodes.toctree)[0]
             if n.get('caption'):
                 sectname = n['caption']
             else:
                 continue
         else:
             # anonymous-only labels
             continue
         labels[name] = docname, labelid, sectname
开发者ID:olivier-heurtier,项目名称:sphinx,代码行数:42,代码来源:std.py

示例14: register_sections_as_label

def register_sections_as_label(app, document):
    # type: (Sphinx, nodes.Node) -> None
    labels = app.env.domaindata['std']['labels']
    anonlabels = app.env.domaindata['std']['anonlabels']
    for node in document.traverse(nodes.section):
        labelid = node['ids'][0]
        docname = app.env.docname
        if app.config.autosectionlabel_prefix_document:
            name = nodes.fully_normalize_name(docname + ':' + node[0].astext())
        else:
            name = nodes.fully_normalize_name(node[0].astext())
        sectname = clean_astext(node[0])

        if name in labels:
            logger.warning('duplicate label %s, ' % name + 'other instance '
                           'in ' + app.env.doc2path(labels[name][0]),
                           location=node)

        anonlabels[name] = docname, labelid
        labels[name] = docname, labelid, sectname
开发者ID:nvmanh,项目名称:plant,代码行数:20,代码来源:autosectionlabel.py

示例15: get_objects

 def get_objects(self):
     # type: () -> Iterator[Tuple[str, str, str, str, str, int]]
     # handle the special 'doc' reference here
     for doc in self.env.all_docs:
         yield (doc, clean_astext(self.env.titles[doc]), 'doc', doc, '', -1)
     for (prog, option), info in self.data['progoptions'].items():
         if prog:
             fullname = ".".join([prog, option])
             yield (fullname, fullname, 'cmdoption', info[0], info[1], 1)
         else:
             yield (option, option, 'cmdoption', info[0], info[1], 1)
     for (type, name), info in self.data['objects'].items():
         yield (name, name, type, info[0], info[1],
                self.object_types[type].attrs['searchprio'])
     for name, info in self.data['labels'].items():
         yield (name, info[2], 'label', info[0], info[1], -1)
     # add anonymous-only labels as well
     non_anon_labels = set(self.data['labels'])
     for name, info in self.data['anonlabels'].items():
         if name not in non_anon_labels:
             yield (name, name, 'label', info[0], info[1], -1)
开发者ID:olivier-heurtier,项目名称:sphinx,代码行数:21,代码来源:std.py


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