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 run(self):
"""For each file in noseOfYeti/specs, output nodes to represent each spec file"""
with hp.a_temp_file() as fle:
fle.write(dedent("""
---
environments: { dev: {account_id: "123"} }
stacks: { app: {} }
""").encode('utf-8'))
fle.seek(0)
collector = Collector()
collector.prepare(fle.name, {'bespin': {'extra': ""}, "command": None, "bash": None})
section = nodes.section()
section['ids'].append("available-tasks")
title = nodes.title()
title += nodes.Text("Default tasks")
section += title
for name, task in sorted(collector.configuration['task_finder'].tasks.items(), key=lambda x: len(x[0])):
lines = [name] + [" {0}".format(line.strip()) for line in task.description.split('\n')]
viewlist = ViewList()
for line in lines:
viewlist.append(line, name)
self.state.nested_parse(viewlist, self.content_offset, section)
return [section]
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['name'] = 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=1)
self.goto_line(newabsoffset)
self.check_section(section_node)
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
['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:
classifier, s, subContent = definitions[child['name']]
if classifier == '@replace':
desc = [s]
elif classifier == '@after':
desc.append(s)
def _section(self, parent, title, id_pattern):
id = id_pattern % self.resource_type
section = nodes.section(ids=[id])
parent.append(section)
title = nodes.title('', title)
section.append(title)
return section
'description', parser_info.get(
'help', "undocumented").capitalize())),
ids=['description-section'])
nested_parse_with_titles(
self.state, self.content, description_section)
if parser_info.get('epilog'):
# TODO: do whatever sphinx does to understand ReST inside
# docstrings magically imported from other places. The nested
# parse method invoked above seem to be able to do this but
# I haven't found a way to do it for arbitrary text
description_section += nodes.paragraph(
text=parser_info['epilog'])
# OPTIONS section
options_section = nodes.section(
'',
nodes.title(text='Options'),
ids=['options-section'])
if 'args' in parser_info:
options_section += nodes.paragraph()
options_section += nodes.subtitle(text='Positional arguments:')
options_section += self._format_positional_arguments(parser_info)
if 'options' in parser_info:
options_section += nodes.paragraph()
options_section += nodes.subtitle(text='Optional arguments:')
options_section += self._format_optional_arguments(parser_info)
items = [
# NOTE: we cannot generate NAME ourselves. It is generated by
# docutils.writers.manpage
synopsis_section,
description_section,
]
if len(options_section.children) > 1:
- boxes -- dict containing (boxname, boxDescription) pairs
"""
items = []
for box in boxes:
try:
description = boxes[box]
except KeyError:
description = ""
except TypeError:
description = "Code uses old style inbox/outbox description - no metadata available"
items.append((str(box), str(description)))
docTree= nodes.section('',
ids = ["symbol-"+componentName+"."+label],
names = ["symbol-"+componentName+"."+label],
*[ nodes.title('', label),
nodes.bullet_list('',
*[ nodes.list_item('', nodes.paragraph('', '',
nodes.strong('', boxname),
nodes.Text(" : "+boxdesc))
)
for (boxname,boxdesc) in items
]
),
]
)
return docTree
# literalblock need literal block notation to avoid it become
# paragraph.
if isinstance(node, LITERAL_TYPE_NODES):
msgstr = '::\n\n' + indent(msgstr, ' ' * 3)
patch = publish_msgstr(self.app, msgstr, source,
node.line, self.config, settings)
# XXX doctest and other block markup
if not isinstance(patch, nodes.paragraph):
continue # skip for now
processed = False # skip flag
# update title(section) target name-id mapping
if isinstance(node, nodes.title):
section_node = node.parent
new_name = nodes.fully_normalize_name(patch.astext())
old_name = nodes.fully_normalize_name(node.astext())
if old_name != new_name:
# if name would be changed, replace node names and
# document nameids mapping with new name.
names = section_node.setdefault('names', [])
names.append(new_name)
# Original section name (reference target name) should be kept to refer
# from other nodes which is still not translated or uses explicit target
# name like "`text to display `_"..
# So, `old_name` is still exist in `names`.
_id = self.document.nameids.get(old_name, None)
explicit = self.document.nametypes.get(old_name, None)
# widths (or basically make the colwidth thing go away
# entirely)
self.options['widths'] = [30, 70]
self.col_widths = self.get_column_widths(self.max_cols)
if isinstance(self.col_widths, tuple):
# In docutils 0.13.1, get_column_widths returns a (widths,
# colwidths) tuple, where widths is a string (i.e. 'auto').
# See https://sourceforge.net/p/docutils/patches/120/.
self.col_widths = self.col_widths[1]
# Actually convert the yaml
title, messages = self.make_title()
# LOG.info("Title %s, messages %s" % (title, messages))
table_node = self.build_table()
self.add_name(table_node)
title_block = nodes.title(
text=status_type.capitalize())
section = nodes.section(ids=title_block)
section += title_block
section += table_node
return [section] + messages
def formatPrefab(self, moduleName, name, X):
CLASSNAME = self.formatPrefabStatement(name)
CLASSDOC = self.docString(X.doc)
return nodes.section('',
* [ nodes.title('', CLASSNAME, ids=["symbol-"+name]) ]
+ CLASSDOC
)