本文整理汇总了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], []
示例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
示例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)
示例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
示例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)], []
示例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], []
示例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
示例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)
示例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)
示例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))
示例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
示例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
示例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
}
示例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
示例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], []