本文整理汇总了Python中docutils.nodes.title方法的典型用法代码示例。如果您正苦于以下问题:Python nodes.title方法的具体用法?Python nodes.title怎么用?Python nodes.title使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类docutils.nodes
的用法示例。
在下文中一共展示了nodes.title方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ensureUniqueIDs
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def ensureUniqueIDs(items):
"""
If action groups are repeated, then links in the table of contents will
just go to the first of the repeats. This may not be desirable, particularly
in the case of subcommands where the option groups have different members.
This function updates the title IDs by adding _repeatX, where X is a number
so that the links are then unique.
"""
s = set()
for item in items:
for n in item.traverse(descend=True, siblings=True, ascend=False):
if isinstance(n, nodes.section):
ids = n['ids']
for idx, id in enumerate(ids):
if id not in s:
s.add(id)
else:
i = 1
while "{}_repeat{}".format(id, i) in s:
i += 1
ids[idx] = "{}_repeat{}".format(id, i)
s.add(ids[idx])
n['ids'] = ids
示例2: new_subsection
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def new_subsection(self, title, lineno, messages):
"""Append new subsection to document tree. On return, check level."""
memo = self.memo
mylevel = memo.section_level
memo.section_level += 1
section_node = nodes.section()
self.parent += section_node
textnodes, title_messages = self.inline_text(title, lineno)
titlenode = nodes.title(title, '', *textnodes)
name = normalize_name(titlenode.astext())
section_node['names'].append(name)
section_node += titlenode
section_node += messages
section_node += title_messages
self.document.note_implicit_target(section_node, section_node)
offset = self.state_machine.line_offset + 1
absoffset = self.state_machine.abs_line_offset() + 1
newabsoffset = self.nested_parse(
self.state_machine.input_lines[offset:], input_offset=absoffset,
node=section_node, match_titles=True)
self.goto_line(newabsoffset)
if memo.section_level <= mylevel: # can't handle next section?
raise EOFError # bubble up to supersection
# reset section_level; next pass will detect it properly
memo.section_level = mylevel
示例3: line
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def line(self, match, context, next_state):
"""Section title overline or transition marker."""
if self.state_machine.match_titles:
return [match.string], 'Line', []
elif match.string.strip() == '::':
raise statemachine.TransitionCorrection('text')
elif len(match.string.strip()) < 4:
msg = self.reporter.info(
'Unexpected possible title overline or transition.\n'
"Treating it as ordinary text because it's so short.",
line=self.state_machine.abs_line_number())
self.parent += msg
raise statemachine.TransitionCorrection('text')
else:
blocktext = self.state_machine.line
msg = self.reporter.severe(
'Unexpected section title or transition.',
nodes.literal_block(blocktext, blocktext),
line=self.state_machine.abs_line_number())
self.parent += msg
return [], next_state, []
示例4: visit_system_message
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def visit_system_message(self, node):
self.requirements['color'] = PreambleCmds.color
self.fallbacks['title'] = PreambleCmds.title
node['classes'] = ['system-message']
self.visit_admonition(node)
self.out.append('\\DUtitle[system-message]{system-message}\n')
self.append_hypertargets(node)
try:
line = ', line~%s' % node['line']
except KeyError:
line = ''
self.out.append('\n\n{\color{red}%s/%s} in \\texttt{%s}%s\n' %
(node['type'], node['level'],
self.encode(node['source']), line))
if len(node['backrefs']) == 1:
self.out.append('\n\\hyperlink{%s}{' % node['backrefs'][0])
self.context.append('}')
else:
backrefs = ['\\hyperlink{%s}{%d}' % (href, i+1)
for (i, href) in enumerate(node['backrefs'])]
self.context.append('backrefs: ' + ' '.join(backrefs))
示例5: run
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def run(self):
set_classes(self.options)
self.assert_has_content()
text = '\n'.join(self.content)
admonition_node = self.node_class(text, **self.options)
self.add_name(admonition_node)
if self.node_class is nodes.admonition:
title_text = self.arguments[0]
textnodes, messages = self.state.inline_text(title_text,
self.lineno)
title = nodes.title(title_text, '', *textnodes)
title.source, title.line = (
self.state_machine.get_source_and_line(self.lineno))
admonition_node += title
admonition_node += messages
if not 'classes' in self.options:
admonition_node['classes'] += ['admonition-' +
nodes.make_id(title_text)]
self.state.nested_parse(self.content, self.content_offset,
admonition_node)
return [admonition_node]
示例6: run
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def run(self):
if not self.content:
error = self.state_machine.reporter.error(
'The "%s" directive is empty; content required.' % self.name,
nodes.literal_block(self.block_text, self.block_text),
line=self.lineno)
return [error]
title, messages = self.make_title()
node = nodes.Element() # anonymous container for parsing
self.state.nested_parse(self.content, self.content_offset, node)
try:
num_cols, widths, col_widths = self.check_list_content(node)
table_data = [[item.children for item in row_list[0]]
for row_list in node[0]]
header_rows = self.options.get('header-rows', 0)
stub_columns = self.options.get('stub-columns', 0)
self.check_table_dimensions(table_data, header_rows, stub_columns)
except SystemMessagePropagation, detail:
return [detail.args[0]]
示例7: run
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def run(self):
if not (self.state_machine.match_titles
or isinstance(self.state_machine.node, nodes.sidebar)):
raise self.error('The "%s" directive may not be used within '
'topics or body elements.' % self.name)
self.assert_has_content()
title_text = self.arguments[0]
textnodes, messages = self.state.inline_text(title_text, self.lineno)
titles = [nodes.title(title_text, '', *textnodes)]
# Sidebar uses this code.
if 'subtitle' in self.options:
textnodes, more_messages = self.state.inline_text(
self.options['subtitle'], self.lineno)
titles.append(nodes.subtitle(self.options['subtitle'], '',
*textnodes))
messages.extend(more_messages)
text = '\n'.join(self.content)
node = self.node_class(text, *(titles + messages))
node['classes'] += self.options.get('class', [])
self.add_name(node)
if text:
self.state.nested_parse(self.content, self.content_offset, node)
return [node]
示例8: make_xref
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def make_xref(self, rolename, domain, target,
innernode=d_nodes.emphasis, contnode=None, env=None):
if not rolename:
return contnode or innernode(target, target)
title = target
if domain == 'eql' and rolename == 'type':
target = EQLTypeXRef.filter_target(target)
if target in EQLTypedField.ignored_types:
return d_nodes.Text(title)
refnode = s_nodes.pending_xref('', refdomain=domain,
refexplicit=title != target,
reftype=rolename, reftarget=target)
refnode += contnode or innernode(title, title)
if env:
env.domains[domain].process_field_xref(refnode)
refnode['eql-auto-link'] = True
return refnode
示例9: genetic_map_section
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def genetic_map_section(self, species, genetic_map):
map_id = self.get_genetic_map_id(species, genetic_map)
target = self.get_target(map_id)
section = nodes.section(ids=[map_id])
section += nodes.title(text=genetic_map.id)
section += nodes.paragraph(text=genetic_map.long_description)
section += nodes.rubric(text="Citations")
section += self.citation_list(genetic_map)
return [target, section]
示例10: model_section
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def model_section(self, species, model):
mid = self.get_demographic_model_id(species, model)
target = self.get_target(mid)
section = nodes.section(ids=[mid])
section += nodes.title(text=model.description)
section += nodes.paragraph(text=model.long_description)
section += nodes.rubric(text="Details")
section += self.model_summary(model)
section += nodes.rubric(text="Populations")
section += self.population_table(model)
section += nodes.rubric(text="Citations")
section += self.citation_list(model)
section += nodes.rubric(text="Demographic Model parameters")
section += self.model_parameter_table(species, model)
return [target, section]
示例11: run
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def run(self):
species = stdpopsim.get_species(self.arguments[0])
sid = f"sec_catalog_{species.id}"
species_target = self.get_target(sid)
section = nodes.section(ids=[sid], names=[sid])
section += nodes.title(text=species.name)
section += self.species_summary(species)
genome_section = nodes.section(ids=[f"sec_catalog_{species.id}_genome"])
genome_section += nodes.title(text="Genome")
genome_section += self.chromosomes_table(species)
section += genome_section
section += nodes.transition()
maps_section = nodes.section(ids=[f"sec_catalog_{species.id}_genetic_maps"])
maps_section += nodes.title(text="Genetic Maps")
maps_section += self.genetic_maps_table(species)
for gmap in species.genetic_maps:
maps_section += self.genetic_map_section(species, gmap)
section += maps_section
section += nodes.transition()
models_section = nodes.section(ids=[f"sec_catalog_{species.id}_models"])
models_section += nodes.title(text="Models")
models_section += self.models_table(species)
for i, model in enumerate(species.demographic_models):
models_section += self.model_section(species, model)
if i < len(species.demographic_models) - 1:
models_section += nodes.transition()
section += models_section
return [species_target, section]
示例12: get_identifier
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def get_identifier(self):
"""Validate and returns disqus_identifier option value.
:returns: disqus_identifier config value.
:rtype: str
"""
if 'disqus_identifier' in self.options:
return self.options['disqus_identifier']
title_nodes = self.state.document.traverse(nodes.title)
if not title_nodes:
raise DisqusError('No title nodes found in document, cannot derive disqus_identifier config value.')
return title_nodes[0].astext()
示例13: apply
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def apply(self):
language = languages.get_language(self.document.settings.language_code,
self.document.reporter)
name = language.labels['contents']
title = nodes.title('', name)
topic = nodes.topic('', title, classes=['contents'])
name = nodes.fully_normalize_name(name)
if not self.document.has_name(name):
topic['names'].append(name)
self.document.note_implicit_target(topic)
pending = nodes.pending(parts.Contents)
topic += pending
self.document.insert(1, topic)
self.document.note_pending(pending)
示例14: cleanup_callback
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def cleanup_callback(self, pending):
"""
Remove an empty "References" section.
Called after the `references.TargetNotes` transform is complete.
"""
if len(pending.parent) == 2: # <title> and <pending>
pending.parent.parent.remove(pending.parent)
示例15: set_metadata
# 需要导入模块: from docutils import nodes [as 别名]
# 或者: from docutils.nodes import title [as 别名]
def set_metadata(self):
"""
Set document['title'] metadata title from the following
sources, listed in order of priority:
* Existing document['title'] attribute.
* "title" setting.
* Document title node (as promoted by promote_title).
"""
if not self.document.hasattr('title'):
if self.document.settings.title is not None:
self.document['title'] = self.document.settings.title
elif len(self.document) and isinstance(self.document[0], nodes.title):
self.document['title'] = self.document[0].astext()