本文整理汇总了Python中docutils.nodes.definition方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.definition方法的具体用法?Python nodes.definition怎么用?Python nodes.definition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.nodes
的用法示例。
在下文中一共展示了nodes.definition方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _format_subcommands
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import definition [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: build_regexp
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import definition [as 别名]
def build_regexp(definition, compile=True):
"""
Build, compile and return a regular expression based on `definition`.
:Parameter: `definition`: a 4-tuple (group name, prefix, suffix, parts),
where "parts" is a list of regular expressions and/or regular
expression definitions to be joined into an or-group.
"""
name, prefix, suffix, parts = definition
part_strings = []
for part in parts:
if type(part) is tuple:
part_strings.append(build_regexp(part, None))
else:
part_strings.append(part)
or_group = '|'.join(part_strings)
regexp = '%(prefix)s(?P<%(name)s>%(or_group)s)%(suffix)s' % locals()
if compile:
return re.compile(regexp, re.UNICODE)
else:
return regexp
示例3: definition_list_item
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import definition [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
示例4: run
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import definition [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 definition [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: map_nested_definitions
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import definition [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
示例7: text
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import definition [as 别名]
def text(self, match, context, next_state):
"""Titles, definition lists, paragraphs."""
return [match.string], 'Text', []
示例8: eof
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import definition [as 别名]
def eof(self, context):
"""Not a definition."""
self.state_machine.previous_line(2) # so parent SM can reassess
return []