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


Python addnodes.only方法代码示例

本文整理汇总了Python中sphinx.addnodes.only方法的典型用法代码示例。如果您正苦于以下问题:Python addnodes.only方法的具体用法?Python addnodes.only怎么用?Python addnodes.only使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sphinx.addnodes的用法示例。


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

示例1: process_only_nodes

# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import only [as 别名]
def process_only_nodes(config, document, tags):
    # type: (nodes.Node, Tags) -> None
    """Filter ``only`` nodes which does not match *tags* or html (through config)"""
    ret_html_cell = config['jupyter_allow_html_only'] 
    for node in document.traverse(addnodes.only):
        try:
            ret = tags.eval_condition(node['expr'])  #check for jupyter only
            if ret_html_cell and node['expr'] == 'html':  #allow html only cells if option is specified
                ret = True
        except Exception as err:
            logger.warning(__('exception while evaluating only directive expression: %s'), err,
                           location=node)
            node.replace_self(node.children or nodes.comment())
        else:
            if ret:
                node.replace_self(node.children or nodes.comment())
            else:
                # A comment on the comment() nodes being inserted: replacing by [] would
                # result in a "Losing ids" exception if there is a target node before
                # the only node, so we make sure docutils can transfer the id to
                # something, even if it's just a comment and will lose the id anyway...
                node.replace_self(nodes.comment()) 
开发者ID:QuantEcon,项目名称:sphinxcontrib-jupyter,代码行数:24,代码来源:__init__.py

示例2: doctree_read

# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import only [as 别名]
def doctree_read(app, doctree):
    # Get the configuration parameters
    if app.config.edit_on_github_project == 'REQUIRED':
        raise ValueError(
            "The edit_on_github_project configuration variable must be "
            "provided in the conf.py")

    source_root = app.config.edit_on_github_source_root
    url = get_url_base(app)

    docstring_message = app.config.edit_on_github_docstring_message

    # Handle the docstring-editing links
    for objnode in doctree.traverse(addnodes.desc):
        if objnode.get('domain') != 'py':
            continue
        names = set()
        for signode in objnode:
            if not isinstance(signode, addnodes.desc_signature):
                continue
            modname = signode.get('module')
            if not modname:
                continue
            fullname = signode.get('fullname')
            if fullname in names:
                # only one link per name, please
                continue
            names.add(fullname)
            obj = import_object(modname, fullname)
            anchor = None
            if obj is not None:
                try:
                    lines, lineno = inspect.getsourcelines(obj)
                except:
                    pass
                else:
                    anchor = '#L%d' % lineno
            if anchor:
                real_modname = inspect.getmodule(obj).__name__
                path = '%s%s%s.py%s' % (
                    url, source_root, real_modname.replace('.', '/'), anchor)
                onlynode = addnodes.only(expr='html')
                onlynode += nodes.reference(
                    reftitle=app.config.edit_on_github_help_message,
                    refuri=path)
                onlynode[0] += nodes.inline(
                    '', '', nodes.raw('', ' ', format='html'),
                    nodes.Text(docstring_message),
                    classes=['edit-on-github', 'viewcode-link'])
                signode += onlynode 
开发者ID:jakevdp,项目名称:supersmoother,代码行数:52,代码来源:edit_on_github.py

示例3: doctree_read

# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import only [as 别名]
def doctree_read(app, doctree):
    env = app.builder.env

    resolve_target = getattr(env.config, 'linkcode_resolve', None)
    if not isinstance(env.config.linkcode_resolve, collections.Callable):
        raise LinkcodeError(
            "Function `linkcode_resolve` is not given in conf.py")

    domain_keys = dict(
        py=['module', 'fullname'],
        c=['names'],
        cpp=['names'],
        js=['object', 'fullname'],
    )

    for objnode in doctree.traverse(addnodes.desc):
        domain = objnode.get('domain')
        uris = set()
        for signode in objnode:
            if not isinstance(signode, addnodes.desc_signature):
                continue

            # Convert signode to a specified format
            info = {}
            for key in domain_keys.get(domain, []):
                value = signode.get(key)
                if not value:
                    value = ''
                info[key] = value
            if not info:
                continue

            # Call user code to resolve the link
            uri = resolve_target(domain, info)
            if not uri:
                # no source
                continue

            if uri in uris or not uri:
                # only one link per name, please
                continue
            uris.add(uri)

            onlynode = addnodes.only(expr='html')
            onlynode += nodes.reference('', '', internal=False, refuri=uri)
            onlynode[0] += nodes.inline('', _('[source]'),
                                        classes=['viewcode-link'])
            signode += onlynode 
开发者ID:nguy,项目名称:artview,代码行数:50,代码来源:linkcode.py


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