當前位置: 首頁>>代碼示例>>Python>>正文


Python roles.XRefRole方法代碼示例

本文整理匯總了Python中sphinx.roles.XRefRole方法的典型用法代碼示例。如果您正苦於以下問題:Python roles.XRefRole方法的具體用法?Python roles.XRefRole怎麽用?Python roles.XRefRole使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sphinx.roles的用法示例。


在下文中一共展示了roles.XRefRole方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setup

# 需要導入模塊: from sphinx import roles [as 別名]
# 或者: from sphinx.roles import XRefRole [as 別名]
def setup(app):
    app.add_config_value('number_figures', True, True)
    app.add_config_value('figure_caption_prefix', "Figure", True)

    app.add_node(page_ref,
                 text=(skip_page_ref, None),
                 html=(skip_page_ref, None),
                 latex=(latex_visit_page_ref, None))

    app.add_role('page', XRefRole(nodeclass=page_ref))

    app.add_node(num_ref,
                 latex=(latex_visit_num_ref, None))

    app.add_role('num', XRefRole(nodeclass=num_ref))

    app.connect("builder-inited", clean_env)
    app.connect('doctree-read', doctree_read)
    app.connect('doctree-resolved', doctree_resolved) 
開發者ID:lofar-astron,項目名稱:factor,代碼行數:21,代碼來源:numfig.py

示例2: brianobj_role

# 需要導入模塊: from sphinx import roles [as 別名]
# 或者: from sphinx.roles import XRefRole [as 別名]
def brianobj_role(role, rawtext, text, lineno, inliner, options={}, content=[]):
    '''
    A Sphinx role, used as a wrapper for the default `py:obj` role, allowing
    us to use the simple backtick syntax for brian classes/functions without
    having to qualify the package for classes/functions that are available after
    a `from brian2 import *`, e.g `NeuronGroup`.
    Also allows to directly link to preference names using the same syntax.
    '''
    if text in prefs:
        linktext = text.replace('_', '-').replace('.', '-')
        text = '%s <brian-pref-%s>' % (text, linktext)
        # Use sphinx's cross-reference role
        xref = XRefRole(warn_dangling=True)
        return xref('std:ref', rawtext, text, lineno, inliner, options, content)
    else:
        if text and (not '~' in text):
            try:
                # A simple class or function name
                if not '.' in text:
                    module = __import__('brian2genn', fromlist=[str(text)])
                    imported = getattr(module, str(text), None)
                    if hasattr(imported, '__module__'):
                        text = '~' + imported.__module__ + '.' + text
                        if inspect.isfunction(imported):
                            text += '()'
                # Possibly a method/classmethod/attribute name
                elif len(text.split('.')) == 2:
                    classname, attrname = text.split('.')
                    # Remove trailing parentheses (will be readded for display)
                    if attrname.endswith('()'):
                        attrname = attrname[:-2]
                    module = __import__('brian2genn', fromlist=[str(classname)])
                    imported = getattr(module, str(classname), None)
                    if hasattr(imported, '__module__'):
                        # Add trailing parentheses only for methods not for
                        # attributes
                        if inspect.ismethod(getattr(imported,
                                                    str(attrname),
                                                    None)):
                            parentheses = '()'
                        else:
                            parentheses = ''

                        text = ('{classname}.{attrname}{parentheses} '
                                '<{modname}.{classname}.{attrname}>').format(classname=classname,
                                                                             attrname=attrname,
                                                                             modname=imported.__module__,
                                                                             parentheses=parentheses)

            except ImportError:
                pass
        role = 'py:obj'
        py_role = PyXRefRole()
        return py_role(role, rawtext, text, lineno, inliner, options, content) 
開發者ID:brian-team,項目名稱:brian2genn,代碼行數:56,代碼來源:briandoc.py


注:本文中的sphinx.roles.XRefRole方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。