本文整理汇总了Python中docutils.nodes.term方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.term方法的具体用法?Python nodes.term怎么用?Python nodes.term使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.nodes
的用法示例。
在下文中一共展示了nodes.term方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _format_subcommands
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import term [as 别名]
def _format_subcommands(self, parser_info):
assert 'children' in parser_info
items = []
for subcmd in parser_info['children']:
subcmd_items = []
if subcmd['help']:
subcmd_items.append(nodes.paragraph(text=subcmd['help']))
else:
subcmd_items.append(nodes.paragraph(text='Undocumented'))
items.append(
nodes.definition_list_item(
'',
nodes.term('', '', nodes.strong(
text=subcmd['bare_usage'])),
nodes.definition('', *subcmd_items)))
return nodes.definition_list('', *items)
示例2: definition_list_item
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import term [as 别名]
def definition_list_item(self, termline):
indented, indent, line_offset, blank_finish = \
self.state_machine.get_indented()
itemnode = nodes.definition_list_item(
'\n'.join(termline + list(indented)))
lineno = self.state_machine.abs_line_number() - 1
(itemnode.source,
itemnode.line) = self.state_machine.get_source_and_line(lineno)
termlist, messages = self.term(termline, lineno)
itemnode += termlist
definition = nodes.definition('', *messages)
itemnode += definition
if termline[0][-2:] == '::':
definition += self.reporter.info(
'Blank line missing before literal block (after the "::")? '
'Interpreted as a definition list item.',
line=lineno+1)
self.nested_parse(indented, input_offset=line_offset, node=definition)
return itemnode, blank_finish
示例3: term
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import term [as 别名]
def term(self, lines, lineno):
"""Return a definition_list's term and optional classifiers."""
assert len(lines) == 1
text_nodes, messages = self.inline_text(lines[0], lineno)
term_node = nodes.term()
(term_node.source,
term_node.line) = self.state_machine.get_source_and_line(lineno)
term_node.rawsource = unescape(lines[0])
node_list = [term_node]
for i in range(len(text_nodes)):
node = text_nodes[i]
if isinstance(node, nodes.Text):
parts = self.classifier_delimiter.split(node.rawsource)
if len(parts) == 1:
node_list[-1] += node
else:
node_list[-1] += nodes.Text(parts[0].rstrip())
for part in parts[1:]:
classifier_node = nodes.classifier('', part)
node_list.append(classifier_node)
else:
node_list[-1] += node
return node_list, messages
示例4: run
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import term [as 别名]
def run(self):
# XXX: do this once only
fd = pkg_resources.resource_stream ('crocoite', 'data/click.yaml')
config = list (yaml.safe_load_all (fd))
l = nodes.definition_list ()
for site in config:
urls = set ()
v = nodes.definition ()
vl = nodes.bullet_list ()
v += vl
for s in site['selector']:
i = nodes.list_item ()
i += nodes.paragraph (text=s['description'])
vl += i
urls.update (map (lambda x: URL(x).with_path ('/'), s.get ('urls', [])))
item = nodes.definition_list_item ()
term = ', '.join (map (lambda x: x.host, urls)) if urls else site['match']
k = nodes.term (text=term)
item += k
item += v
l += item
return [l]
示例5: _create_section
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import term [as 别名]
def _create_section(self, parent, sectionid, title=None, term=None):
"""Create a new section
:returns: If term is specified, returns a definition node contained
within the newly created section. Otherwise return the newly created
section node.
"""
idb = nodes.make_id(sectionid)
section = nodes.section(ids=[idb])
parent.append(section)
if term:
if term != '**':
section.append(nodes.term('', term))
definition = nodes.definition()
section.append(definition)
return definition
if title:
section.append(nodes.title('', title))
return section
示例6: term
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import term [as 别名]
def term(self, lines, lineno):
"""Return a definition_list's term and optional classifiers."""
assert len(lines) == 1
text_nodes, messages = self.inline_text(lines[0], lineno)
term_node = nodes.term(lines[0])
(term_node.source,
term_node.line) = self.state_machine.get_source_and_line(lineno)
node_list = [term_node]
for i in range(len(text_nodes)):
node = text_nodes[i]
if isinstance(node, nodes.Text):
parts = self.classifier_delimiter.split(node)
if len(parts) == 1:
node_list[-1] += node
else:
text = parts[0].rstrip()
textnode = nodes.Text(utils.unescape(text, True))
node_list[-1] += textnode
for part in parts[1:]:
node_list.append(
nodes.classifier(unescape(part, True), part))
else:
node_list[-1] += node
return node_list, messages
示例7: map_nested_definitions
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import term [as 别名]
def map_nested_definitions(nested_content):
if nested_content is None:
raise Exception('Nested content should be iterable, not null')
# build definition dictionary
definitions = {}
for item in nested_content:
if not isinstance(item, nodes.definition_list):
continue
for subitem in item:
if not isinstance(subitem, nodes.definition_list_item):
continue
if not len(subitem.children) > 0:
continue
classifier = '@after'
idx = subitem.first_child_matching_class(nodes.classifier)
if idx is not None:
ci = subitem[idx]
if len(ci.children) > 0:
classifier = ci.children[0].astext()
if classifier is not None and classifier not in (
'@replace', '@before', '@after'):
raise Exception('Unknown classifier: %s' % classifier)
idx = subitem.first_child_matching_class(nodes.term)
if idx is not None:
term = subitem[idx]
if len(term.children) > 0:
term = term.children[0].astext()
idx = subitem.first_child_matching_class(nodes.definition)
if idx is not None:
subContent = []
for _ in subitem[idx]:
if isinstance(_, nodes.definition_list):
subContent.append(_)
definitions[term] = (classifier, subitem[idx].astext(), subContent)
return definitions
示例8: warn_indirect_terms
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import term [as 别名]
def warn_indirect_terms(cls, app, exception):
"""
Output a warning for each cross-reference to a term that
consists only of a "see:" paragraph. These cross-references
should be changed in the source text to refer to the target of
the "see:".
"""
if not exception:
for i in cls.see_only_ids:
for doc, line in cls.xref_ids[i]:
print('{}:{}: WARNING: cross-reference to {}.'
.format(doc, line, i))
示例9: map_nested_definitions
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import term [as 别名]
def map_nested_definitions(nested_content):
if nested_content is None:
raise Exception('Nested content should be iterable, not null')
# build definition dictionary
definitions = {}
for item in nested_content:
if not isinstance(item, nodes.definition_list):
continue
for subitem in item:
if not isinstance(subitem, nodes.definition_list_item):
continue
if not len(subitem.children) > 0:
continue
classifier = '@after'
idx = subitem.first_child_matching_class(nodes.classifier)
if idx is not None:
ci = subitem[idx]
if len(ci.children) > 0:
classifier = ci.children[0].astext()
if classifier is not None and classifier not in (
'@replace', '@before', '@after'):
raise Exception('Unknown classifier: %s' % classifier)
idx = subitem.first_child_matching_class(nodes.term)
if idx is not None:
ch = subitem[idx]
if len(ch.children) > 0:
term = ch.children[0].astext()
idx = subitem.first_child_matching_class(nodes.definition)
if idx is not None:
def_node = subitem[idx]
def_node.attributes['classifier'] = classifier
definitions[term] = def_node
return definitions
示例10: print_command_args_and_opts
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import term [as 别名]
def print_command_args_and_opts(arg_list, opt_list, sub_list=None):
items = []
if arg_list:
items.append(nodes.definition_list_item(
'', nodes.term(text='Positional arguments:'),
nodes.definition('', arg_list)))
if opt_list:
items.append(nodes.definition_list_item(
'', nodes.term(text='Options:'),
nodes.definition('', opt_list)))
if sub_list and len(sub_list):
items.append(nodes.definition_list_item(
'', nodes.term(text='Sub-commands:'),
nodes.definition('', sub_list)))
return nodes.definition_list('', *items)
示例11: print_subcommand_list
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import term [as 别名]
def print_subcommand_list(data, nested_content):
definitions = map_nested_definitions(nested_content)
items = []
if 'children' in data:
for child in data['children']:
my_def = [nodes.paragraph(
text=child['help'])] if child['help'] else []
name = child['name']
my_def = apply_definition(definitions, my_def, name)
if len(my_def) == 0:
my_def.append(nodes.paragraph(text='Undocumented'))
if 'description' in child:
my_def.append(nodes.paragraph(text=child['description']))
my_def.append(nodes.literal_block(text=child['usage']))
my_def.append(print_command_args_and_opts(
print_arg_list(child, nested_content),
print_opt_list(child, nested_content),
print_subcommand_list(child, nested_content)
))
items.append(
nodes.definition_list_item(
'',
nodes.term('', '', nodes.strong(text=name)),
nodes.definition('', *my_def)
)
)
return nodes.definition_list('', *items)