本文整理汇总了Python中sphinx.addnodes.desc方法的典型用法代码示例。如果您正苦于以下问题:Python addnodes.desc方法的具体用法?Python addnodes.desc怎么用?Python addnodes.desc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sphinx.addnodes
的用法示例。
在下文中一共展示了addnodes.desc方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_target_and_index
# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import desc [as 别名]
def add_target_and_index(self, name: str, sig: str,
signodes: addnodes.desc) -> None:
"""Add to index and to domain data"""
target_name = "-".join((self.objtype, name))
if target_name not in self.state.document.ids:
signodes['names'].append(target_name)
signodes['ids'].append(target_name)
signodes['first'] = (not self.names)
self.state.document.note_explicit_target(signodes)
objects = self.env.domaindata[self.domain]['objects']
key = (self.objtype, name)
if key in objects:
if hasattr(self.env, 'warn'):
self.env.warn(
self.env.docname,
"Duplicate entry {} {} at {} (other in {})".format(
self.objtype, name, self.lineno,
self.env.doc2path(objects[key][0])))
objects[key] = (self.env.docname, target_name)
index_text = self.get_index_text(name)
if index_text:
self.indexnode['entries'].append(('single', index_text, target_name, '', None))
示例2: run
# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import desc [as 别名]
def run(self):
index, desc = super().run()
assert isinstance(desc, addnodes.desc)
desc_content = desc[1]
assert isinstance(desc_content, addnodes.desc_content)
return desc_content.children[1:] #don't include the summary table/list/reference
示例3: handle_signature
# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import desc [as 别名]
def handle_signature(self, sig: str, signode: addnodes.desc) -> str:
"""Transform signature into RST nodes"""
signode += addnodes.desc_annotation(self.typename, self.typename + " ")
signode += addnodes.desc_name(sig, sig)
if 'badges' in self.options:
badges = addnodes.desc_annotation()
badges['classes'] += ['badges']
content = StringList([self.options['badges']])
self.state.nested_parse(content, 0, badges)
signode += badges
if 'replaces_section_title' in self.options:
section = self.state.parent
if isinstance(section, nodes.section):
title = section[-1]
if isinstance(title, nodes.title):
section.remove(title)
else:
signode += self.state.document.reporter.warning(
"%s:%s:: must follow section directly to replace section title"
% (self.domain, self.objtype), line = self.lineno
)
else:
signode += self.state.document.reporter.warning(
"%s:%s:: must be in section to replace section title"
% (self.domain, self.objtype), line = self.lineno
)
return sig
示例4: insert_field_list
# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import desc [as 别名]
def insert_field_list(node: Element) -> nodes.field_list:
field_list = nodes.field_list()
desc = [n for n in node if isinstance(n, addnodes.desc)]
if desc:
# insert just before sub object descriptions (ex. methods, nested classes, etc.)
index = node.index(desc[0])
node.insert(index - 1, [field_list])
else:
node += field_list
return field_list
示例5: make_process_header
# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import desc [as 别名]
def make_process_header(self, slug, typ, version, source_uri, description, inputs):
"""Generate a process definition header.
:param str slug: process' slug
:param str typ: process' type
:param str version: process' version
:param str source_uri: url to the process definition
:param str description: process' description
:param dict inputs: process' inputs
"""
node = addnodes.desc()
signode = addnodes.desc_signature(slug, "")
node.append(signode)
node["objtype"] = node["desctype"] = typ
signode += addnodes.desc_annotation(typ, typ, classes=["process-type"])
signode += addnodes.desc_addname("", "")
signode += addnodes.desc_name(slug + " ", slug + " ")
paramlist = addnodes.desc_parameterlist()
for field_schema, _, _ in iterate_schema({}, inputs, ""):
field_type = field_schema["type"]
field_name = field_schema["name"]
field_default = field_schema.get("default", None)
field_default = "" if field_default is None else "={}".format(field_default)
param = addnodes.desc_parameter("", "", noemph=True)
param += nodes.emphasis(field_type, field_type, classes=["process-type"])
# separate by non-breaking space in the output
param += nodes.strong(text="\xa0\xa0" + field_name)
paramlist += param
signode += paramlist
signode += nodes.reference(
"",
nodes.Text("[Source: v{}]".format(version)),
refuri=source_uri,
classes=["viewcode-link"],
)
desc = nodes.paragraph()
desc += nodes.Text(description, description)
return [node, desc]
示例6: doctree_read
# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import desc [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
示例7: doctree_read
# 需要导入模块: from sphinx import addnodes [as 别名]
# 或者: from sphinx.addnodes import desc [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