Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def apply(self):
doc = self.document
i = len(doc) - 1
refsect = copyright = None
while i >= 0 and isinstance(doc[i], nodes.section):
title_words = doc[i][0].astext().lower().split()
if 'references' in title_words:
refsect = doc[i]
break
elif 'copyright' in title_words:
copyright = i
i -= 1
if not refsect:
refsect = nodes.section()
refsect += nodes.title('', 'References')
doc.set_id(refsect)
if copyright:
# Put the new "References" section before "Copyright":
doc.insert(copyright, refsect)
else:
# Put the new "References" section at end of doc:
doc.append(refsect)
pending = nodes.pending(references.TargetNotes)
refsect.append(pending)
self.document.note_pending(pending, 0)
pending = nodes.pending(misc.CallBack,
details={'callback': self.cleanup_callback})
refsect.append(pending)
self.document.note_pending(pending, 1)
def _render_service(self, service):
service_id = "service-%d" % self.env.new_serialno('service')
service_node = nodes.section(ids=[service_id])
title = '%s service at %s' % (service.name.title(), service.path)
service_node += nodes.title(text=title)
if service.description is not None:
service_node += rst2node(trim(service.description))
for method, view, args in service.definitions:
if method == 'HEAD':
# Skip head - this is essentially duplicating the get docs.
continue
method_id = '%s-%s' % (service_id, method)
method_node = nodes.section(ids=[method_id])
method_node += nodes.title(text=method)
docstring = self._resolve_obj_to_docstring(view, args)
# download file
rst.append(":download:`{}<{}>`".format(
op.basename(full_path), full_path))
# code
rst.append("")
rst.append(".. code-block:: python")
rst.append(" :linenos:")
rst.append("")
for line in code:
rst.append(" {}".format(line))
rst.append("")
vl = ViewList(rst, "fakefile.rst")
# Create a node.
node = nodes.section()
node.document = self.state.document
# Parse the rst.
nested_parse_with_titles(self.state, vl, node)
return node.children
def print_subcommands(data, nested_content, markDownHelp=False):
"""
Each subcommand is a dictionary with the following keys:
['usage', 'action_groups', 'bare_usage', 'name', 'help', 'epilog']
In essence, this is all tossed in a new section with the title 'name'.
Apparently there can also be a 'description' entry.
"""
definitions = map_nested_definitions(nested_content)
items = []
if 'children' in data:
subCommands = nodes.section(ids=["Sub-commands:"])
subCommands += nodes.title('Sub-commands:', 'Sub-commands:')
for child in data['children']:
sec = nodes.section(ids=[child['name']])
sec += nodes.title(child['name'], child['name'])
if 'description' in child and child['description']:
desc = [child['description']]
elif child['help']:
desc = [child['help']]
else:
desc = ['Undocumented']
# Handle nested content
subContent = []
if child['name'] in definitions:
iface_map = {iface_type: api_map.get(iface_type)}
result = ViewList()
for api_path, api_ref, api_methods in _format_apis(iface_map):
result.append(api_path, source_name)
result.append('', source_name)
result.append(api_ref, source_name)
result.append('', source_name)
for method in api_methods:
result.append(method, source_name)
result.append('', source_name)
# Parse what we have into a new section.
node = nodes.section()
node.document = self.state.document
nested_parse_with_titles(self.state, result, node)
return node.children
def run(self):
source = '\n'.join(self.content.data)
literal = nodes.literal_block(source, source)
literal['visualnodetype'] = True
literal['language'] = 'python'
# docutils document model is insane!
head1 = nodes.paragraph()
introduction = self.options.pop('introduction', "Example:")
head1.append(nodes.inline(introduction, introduction))
inter = self.options.pop('inter', "Outputs:")
head2 = nodes.paragraph()
head2.append(
nodes.section("foo", nodes.inline(inter, inter))
)
directive_nodes = [
head1,
literal,
head2,
self.get_image_node(source)
]
return directive_nodes
def visit_table(self, node):
self.requirements['table'] = PreambleCmds.table
if self.active_table.is_open():
self.table_stack.append(self.active_table)
# nesting longtable does not work (e.g. 2007-04-18)
self.active_table = Table(self,'tabular',self.settings.table_style)
# A longtable moves before \paragraph and \subparagraph
# section titles if it immediately follows them:
if (self.active_table._latex_type == 'longtable' and
isinstance(node.parent, nodes.section) and
node.parent.index(node) == 1 and
self.d_class.section(self.section_level).find('paragraph') != -1):
self.out.append('\\leavevmode')
self.active_table.open()
for cls in node['classes']:
self.active_table.set_table_style(cls)
if self.active_table._table_style == 'booktabs':
self.requirements['booktabs'] = r'\usepackage{booktabs}'
self.push_output_collector([])
def candidate_index(self, node):
"""
Find and return the promotion candidate and its index.
Return (None, None) if no valid candidate was found.
"""
index = node.first_child_not_matching_class(
nodes.PreBibliographic)
if index is None or len(node) > (index + 1) or \
not isinstance(node[index], nodes.section):
return None, None
else:
return node[index], index
node['classes'] = ['lit-container']
node.document = self.state.document
enum = nodes.enumerated_list()
enum['classes'] = ['lit-docs']
node.append(enum)
# make first list item
list_item = nodes.list_item()
list_item['classes'] = ['lit-item']
for is_doc, line in lines:
if is_doc and line == ['']:
continue
section = nodes.section()
if is_doc:
section['classes'] = ['lit-annotation']
nested_parse_with_titles(self.state, ViewList(line), section)
else:
section['classes'] = ['lit-content']
code = '\n'.join(line)
literal = nodes.literal_block(code, code)
literal['language'] = 'yaml'
set_source_info(self, literal)
section.append(literal)
list_item.append(section)
def depart_title(self, node):
if isinstance(node.parent, nodes.section):
char = self._title_char
else:
char = '^'
text = ''.join(x[1] for x in self.states.pop() if x[0] == -1)
self.stateindent.pop()
self.states[-1].append((0, ['', text, '%s' % (char * len(text)), '']))