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


Python nodes.reference方法代碼示例

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


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

示例1: tl_role

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def tl_role(name, rawtext, text, lineno, inliner, options=None, content=None):
    """
    Link to the TL reference.

    Returns 2 part tuple containing list of nodes to insert into the
    document and a list of system messages. Both are allowed to be empty.

    :param name: The role name used in the document.
    :param rawtext: The entire markup snippet, with role.
    :param text: The text marked with the role.
    :param lineno: The line number where rawtext appears in the input.
    :param inliner: The inliner instance that called us.
    :param options: Directive options for customization.
    :param content: The directive content for customization.
    """
    if options is None:
        options = {}

    # TODO Report error on type not found?
    # Usage:
    #   msg = inliner.reporter.error(..., line=lineno)
    #   return [inliner.problematic(rawtext, rawtext, msg)], [msg]
    app = inliner.document.settings.env.app
    node = make_link_node(rawtext, app, text, options)
    return [node], [] 
開發者ID:LonamiWebs,項目名稱:Telethon,代碼行數:27,代碼來源:custom_roles.py

示例2: make_field_list

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def make_field_list(self, data):

        field_list = nodes.field_list()
        for name, text, citations in data:
            field = nodes.field()
            field_name = nodes.field_name(text=name)
            field_body = nodes.field_body()
            para = nodes.paragraph(text=text)

            if citations is not None and len(citations) > 0:
                para += nodes.Text(" (")
                for i, citation in enumerate(citations):
                    text = f"{citation.author}, {citation.year}"
                    para += nodes.reference(
                        internal=False, refuri=citation.doi, text=text)
                    if i != len(citations)-1:
                        para += nodes.Text("; ")
                para += nodes.Text(")")

            field_body += para
            field += field_name
            field += field_body
            field_list += field

        return field_list 
開發者ID:popsim-consortium,項目名稱:stdpopsim,代碼行數:27,代碼來源:speciescatalog.py

示例3: make_link_node

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def make_link_node(rawtext, app, url_type, link_text, slug, options):
  """
  Creates a link to a trac ticket.

  :param rawtext: text being replaced with link node
  :param app: sphinx application context
  :param url_type: base for our url
  :param link_text: text for the link
  :param slug: ID of the thing to link to
  :param options: options dictionary passed to role func
  """

  base_url = getattr(app.config, url_type, None)

  if not base_url:
    raise ValueError("'%s' isn't set in our config" % url_type)

  ref = base_url.format(slug = slug)
  set_classes(options)

  return reference(rawtext, link_text, refuri = ref, **options) 
開發者ID:torproject,項目名稱:stem,代碼行數:23,代碼來源:roles.py

示例4: mask_email

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def mask_email(ref, pepno=None):
    """
    Mask the email address in `ref` and return a replacement node.

    `ref` is returned unchanged if it contains no email address.

    For email addresses such as "user@host", mask the address as "user at
    host" (text) to thwart simple email address harvesters (except for those
    listed in `non_masked_addresses`).  If a PEP number (`pepno`) is given,
    return a reference including a default email subject.
    """
    if ref.hasattr('refuri') and ref['refuri'].startswith('mailto:'):
        if ref['refuri'][8:] in non_masked_addresses:
            replacement = ref[0]
        else:
            replacement_text = ref.astext().replace('@', ' at ')
            replacement = nodes.raw('', replacement_text, format='html')
        if pepno is None:
            return replacement
        else:
            ref['refuri'] += '?subject=PEP%%20%s' % pepno
            ref[:] = [replacement]
            return ref
    else:
        return ref 
開發者ID:skarlekar,項目名稱:faces,代碼行數:27,代碼來源:peps.py

示例5: pep_reference_role

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def pep_reference_role(role, rawtext, text, lineno, inliner,
                       options={}, content=[]):
    try:
        pepnum = int(text)
        if pepnum < 0 or pepnum > 9999:
            raise ValueError
    except ValueError:
        msg = inliner.reporter.error(
            'PEP number must be a number from 0 to 9999; "%s" is invalid.'
            % text, line=lineno)
        prb = inliner.problematic(rawtext, rawtext, msg)
        return [prb], [msg]
    # Base URL mainly used by inliner.pep_reference; so this is correct:
    ref = (inliner.document.settings.pep_base_url
           + inliner.document.settings.pep_file_url_template % pepnum)
    set_classes(options)
    return [nodes.reference(rawtext, 'PEP ' + utils.unescape(text), refuri=ref,
                            **options)], [] 
開發者ID:skarlekar,項目名稱:faces,代碼行數:20,代碼來源:roles.py

示例6: rfc_reference_role

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def rfc_reference_role(role, rawtext, text, lineno, inliner,
                       options={}, content=[]):
    try:
        rfcnum = int(text)
        if rfcnum <= 0:
            raise ValueError
    except ValueError:
        msg = inliner.reporter.error(
            'RFC number must be a number greater than or equal to 1; '
            '"%s" is invalid.' % text, line=lineno)
        prb = inliner.problematic(rawtext, rawtext, msg)
        return [prb], [msg]
    # Base URL mainly used by inliner.rfc_reference, so this is correct:
    ref = inliner.document.settings.rfc_base_url + inliner.rfc_url % rfcnum
    set_classes(options)
    node = nodes.reference(rawtext, 'RFC ' + utils.unescape(text), refuri=ref,
                           **options)
    return [node], [] 
開發者ID:skarlekar,項目名稱:faces,代碼行數:20,代碼來源:roles.py

示例7: substitution_reference

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def substitution_reference(self, match, lineno):
        before, inlines, remaining, sysmessages, endstring = self.inline_obj(
              match, lineno, self.patterns.substitution_ref,
              nodes.substitution_reference)
        if len(inlines) == 1:
            subref_node = inlines[0]
            if isinstance(subref_node, nodes.substitution_reference):
                subref_text = subref_node.astext()
                self.document.note_substitution_ref(subref_node, subref_text)
                if endstring[-1:] == '_':
                    reference_node = nodes.reference(
                        '|%s%s' % (subref_text, endstring), '')
                    if endstring[-2:] == '__':
                        reference_node['anonymous'] = 1
                    else:
                        reference_node['refname'] = normalize_name(subref_text)
                        self.document.note_refname(reference_node)
                    reference_node += subref_node
                    inlines = [reference_node]
        return before, inlines, remaining, sysmessages 
開發者ID:skarlekar,項目名稱:faces,代碼行數:22,代碼來源:states.py

示例8: parse_target

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def parse_target(self, block, block_text, lineno):
        """
        Determine the type of reference of a target.

        :Return: A 2-tuple, one of:

            - 'refname' and the indirect reference name
            - 'refuri' and the URI
            - 'malformed' and a system_message node
        """
        if block and block[-1].strip()[-1:] == '_': # possible indirect target
            reference = ' '.join([line.strip() for line in block])
            refname = self.is_reference(reference)
            if refname:
                return 'refname', refname
        reference = ''.join([''.join(line.split()) for line in block])
        return 'refuri', unescape(reference) 
開發者ID:skarlekar,項目名稱:faces,代碼行數:19,代碼來源:states.py

示例9: stylesheet_call

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def stylesheet_call(self, path):
        """Return code to reference or embed stylesheet file `path`"""
        if self.settings.embed_stylesheet:
            try:
                content = io.FileInput(source_path=path,
                                       encoding='utf-8').read()
                self.settings.record_dependencies.add(path)
            except IOError as err:
                msg = "Cannot embed stylesheet '%s': %s." % (
                                path, SafeString(err.strerror))
                self.document.reporter.error(msg)
                return '<--- %s --->\n' % msg
            return self.embedded_stylesheet % content
        # else link to style file:
        if self.settings.stylesheet_path:
            # adapt path relative to output (cf. config.html#stylesheet-path)
            path = utils.relative_path(self.settings._destination, path)
        return self.stylesheet_link % self.encode(path) 
開發者ID:skarlekar,項目名稱:faces,代碼行數:20,代碼來源:_html_base.py

示例10: visit_reference

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def visit_reference(self, node):
        atts = {'class': 'reference'}
        if 'refuri' in node:
            atts['href'] = node['refuri']
            if ( self.settings.cloak_email_addresses
                 and atts['href'].startswith('mailto:')):
                atts['href'] = self.cloak_mailto(atts['href'])
                self.in_mailto = True
            atts['class'] += ' external'
        else:
            assert 'refid' in node, \
                   'References must have "refuri" or "refid" attribute.'
            atts['href'] = '#' + node['refid']
            atts['class'] += ' internal'
        if not isinstance(node.parent, nodes.TextElement):
            assert len(node) == 1 and isinstance(node[0], nodes.image)
            atts['class'] += ' image-reference'
        self.body.append(self.starttag(node, 'a', '', **atts)) 
開發者ID:skarlekar,項目名稱:faces,代碼行數:20,代碼來源:_html_base.py

示例11: resolve_required_by_xrefs

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def resolve_required_by_xrefs(app, env, node, contnode):
    """Now that all recipes and packages have been parsed, we are called here
    for each ``pending_xref`` node that sphinx has not been able to resolve.

    We handle specifically the ``requiredby`` reftype created by the
    `RequiredByField` fieldtype allowed in ``conda:package::``
    directives, where we replace the ``pending_ref`` node with a bullet
    list of reference nodes pointing to the package pages that
    "depended" on the package.
    """
    if node['reftype'] == 'requiredby' and node['refdomain'] == 'conda':
        target = node['reftarget']
        docname = node['refdoc']
        backrefs = env.domains['conda'].data['backrefs'].get(target, set())
        listnode = nodes.bullet_list()
        for back_docname, back_target in backrefs:
            par = nodes.paragraph()
            name_node = addnodes.literal_strong(back_target, back_target,
                                      classes=['xref', 'backref'])
            refnode = make_refnode(app.builder, docname,
                                   back_docname, back_target, name_node)
            refnode.set_class('conda-package')
            par += refnode
            listnode += nodes.list_item('', par)
        return listnode 
開發者ID:bioconda,項目名稱:bioconda-utils,代碼行數:27,代碼來源:sphinxext.py

示例12: resolve_xref

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def resolve_xref(self, env: BuildEnvironment, fromdocname: str,
                     builder, role, target, node, contnode):
        """Resolve the ``pending_xref`` **node** with the given **role** and **target**."""
        for objtype in self.objtypes_for_role(role) or []:
            if (objtype, target) in self.data['objects']:
                node = make_refnode(
                    builder, fromdocname,
                    self.data['objects'][objtype, target][0],
                    self.data['objects'][objtype, target][1],
                    contnode, target + ' ' + objtype)
                node.set_class('conda-package')
                return node

            if objtype == "package":
                for channel, urlformat in env.app.config.bioconda_other_channels.items():
                    if RepoData().get_package_data(channels=channel, name=target):
                        uri = urlformat.format(target)
                        node = nodes.reference('', '', internal=False,
                                               refuri=uri, classes=[channel])
                        node += contnode
                        return node

        return None  # triggers missing-reference 
開發者ID:bioconda,項目名稱:bioconda-utils,代碼行數:25,代碼來源:sphinxext.py

示例13: setup

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def setup(app):
    """Set up sphinx extension"""
    app.add_domain(CondaDomain)
    app.add_directive('autorecipes', AutoRecipesDirective)
    app.add_directive('lint-check', LintDescriptionDirective)
    app.connect('builder-inited', generate_recipes)
    app.connect('env-updated', LintDescriptionDirective.finalize)
    app.connect('missing-reference', resolve_required_by_xrefs)
    app.connect('html-page-context', add_ribbon)
    app.add_config_value('bioconda_repo_url', '', 'env')
    app.add_config_value('bioconda_recipes_path', 'recipes', 'env')
    app.add_config_value('bioconda_config_file', 'config.yml', 'env')
    app.add_config_value('bioconda_other_channels', {}, 'env')
    return {
        'version': "0.0.1",
        'parallel_read_safe': True,
        'parallel_write_safe': True
    } 
開發者ID:bioconda,項目名稱:bioconda-utils,代碼行數:20,代碼來源:sphinxext.py

示例14: make_link_node

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def make_link_node(rawtext, app, name, options):
    """
    Create a link to the TL reference.

    :param rawtext: Text being replaced with link node.
    :param app: Sphinx application context
    :param name: Name of the object to link to
    :param options: Options dictionary passed to role func.
    """
    try:
        base = app.config.tl_ref_url
        if not base:
            raise AttributeError
    except AttributeError as e:
        raise ValueError('tl_ref_url config value is not set') from e

    if base[-1] != '/':
        base += '/'

    set_classes(options)
    node = nodes.reference(rawtext, utils.unescape(name),
                           refuri='{}?q={}'.format(base, name),
                           **options)
    return node


# noinspection PyUnusedLocal 
開發者ID:LonamiWebs,項目名稱:Telethon,代碼行數:29,代碼來源:custom_roles.py

示例15: pull_role

# 需要導入模塊: from docutils import nodes [as 別名]
# 或者: from docutils.nodes import reference [as 別名]
def pull_role(name, rawtext, text, lineno, inliner, options={}, content=[]):
    ref = 'https://github.com/pulse2percept/pulse2percept/pull/' + text
    set_classes(options)
    node = nodes.reference(rawtext, 'PR #' + text, refuri=ref, **options)
    return [node], [] 
開發者ID:pulse2percept,項目名稱:pulse2percept,代碼行數:7,代碼來源:p2pdocs.py


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