Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#Identifies the version of our extension
return {'version': '0.1'}
def visit_tag_node(self, node):
self.visit_admonition(node)
def depart_tag_node(self, node):
self.depart_admonition(node)
def purge_tags(app, env, docname):
return
def process_tag_nodes(app, doctree, fromdocname):
env = app.builder.env
class tag (nodes.Admonition, nodes.Element):
pass
class TagDirective(Directive):
#This allows content in the directive, e.g. to list tags here
has_content = True
def run(self):
env = self.state.document.settings.env
targetid = "tag-%d" % env.new_serialno('tag')
targetnode = nodes.target('', '', ids=[targetid])
#the tags fetched from the custom directive are one piece of text
#sitting in self.content[0]
taggs = self.content[0].split(", ")
links = []
# Licensed under a 3-clause BSD style license - see LICENSE.rst
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, unicode_literals, print_function
from docutils import nodes
class category(nodes.Element):
pass
def category_role(name, rawtext, text, lineno, inliner,
options={}, content=[]):
node = category(text)
return [node], []
def visit_category_node_html(self, node):
self.body.append('<span class="category">')
self.body.append(node.rawsource)
def depart_category_node_html(self, node):
self.body.append('</span>')
def add_caption(self, caption_string, node):
cnode = nodes.Element() # anonymous container for parsing
sl = statemachine.StringList([caption_string], source='')
self.state.nested_parse(sl, self.content_offset, cnode)
caption = nodes.caption(caption_string, '', *cnode)
if 'align' in self.options:
caption['align'] = self.options['align']
else:
caption['align'] = 'center'
node += caption
try:
i = PIL.open(str(image_node['uri']))
except (IOError, UnicodeError):
pass
else:
self.state.document.settings.record_dependencies.add(
image_node['uri'])
figure_node['width'] = i.size[0]
elif figwidth is not None:
figure_node['width'] = figwidth
if figclasses:
figure_node['classes'] += figclasses
if align:
figure_node['align'] = align
if self.content:
node = nodes.Element() # anonymous container for parsing
self.state.nested_parse(self.content, self.content_offset, node)
first_node = node[0]
if isinstance(first_node, nodes.paragraph):
caption = nodes.caption(first_node.rawsource, '',
*first_node.children)
figure_node += caption
elif not (isinstance(first_node, nodes.comment)
and len(first_node) == 0):
error = self.state_machine.reporter.error(
'Figure caption must be a paragraph or empty comment.',
nodes.literal_block(self.block_text, self.block_text),
line=self.lineno)
return [figure_node, error]
if len(node) > 1:
figure_node += nodes.legend('', *node[1:])
return [figure_node]
node.tabnode_options["active"] = ""
res = TABDIV_BEGIN % {
"divid": divid,
"tabname": tabname,
"active": node.tabnode_options["active"],
}
self.body.append(res)
def depart_tab_node(self, node):
# Set options and format templates accordingly
self.body.append(TABDIV_END)
class TabbedStuffNode(nodes.General, nodes.Element, RunestoneNode):
"""A TabbedStuffNode contains one or more TabNodes"""
def __init__(self, content, **kwargs):
super(TabbedStuffNode, self).__init__(**kwargs)
self.tabbed_stuff_options = content
self.divid = content["divid"]
def visit_tabbedstuff_node(self, node):
divid = node.divid
if "inactive" in node.tabbed_stuff_options:
node.tabbed_stuff_options["inactive"] = "data-inactive"
else:
node.tabbed_stuff_options["inactive"] = ""
res = BEGIN % {
__author__ = 'magreene'
import collections
import re
from docutils import nodes
from docutils.parsers.rst import Directive
from docutils.statemachine import StringList
class progress(nodes.General, nodes.Element):
tagname = 'progress'
class ProgressTable(Directive):
has_content = True
required_arguments = 1
final_argument_whitespace = True
option_spec = {'text': str}
def create_headrow(self, label="Progress", classes=('prog-top-label',)):
hrow = nodes.row()
hrow += nodes.entry('', nodes.paragraph(text=label), classes=['head'] + list(classes))
hrow += nodes.entry('', nodes.paragraph(text='PLACEHOLDER'), classes=['PLACEHOLDER'])
return hrow
def create_progtable(self, **attrs):
error = state_machine.reporter.error(
'Empty meta directive.',
nodes.literal_block(block_text, block_text), line=lineno)
node += error
return node.children
meta.content = 1
def imagemap(name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
return []
class MetaBody(states.SpecializedBody):
class meta(nodes.Special, nodes.PreBibliographic, nodes.Element):
"""HTML-specific "meta" element."""
pass
def field_marker(self, match, context, next_state):
"""Meta element."""
node, blank_finish = self.parsemeta(match)
self.parent += node
return [], next_state, []
def parsemeta(self, match):
name = self.parse_field_marker(match)
indented, indent, line_offset, blank_finish = \
self.state_machine.get_first_known_indented(match.end())
node = self.meta()
pending = nodes.pending(components.Filter,
{'component': 'writer',
class hlist(nodes.Element):
"""Node for "horizontal lists", i.e. lists that should be compressed to
take up less vertical space.
"""
class hlistcol(nodes.Element):
"""Node for one column in a horizontal list."""
class compact_paragraph(nodes.paragraph):
"""Node for a compact paragraph (which never makes a <p> node)."""
class glossary(nodes.Element):
"""Node to insert a glossary."""
class only(nodes.Element):
"""Node for "only" directives (conditional inclusion based on tags)."""
# meta-information nodes
class start_of_file(nodes.Element):
"""Node to mark start of a new file, used in the LaTeX builder only."""
class highlightlang(nodes.Element):
"""Inserted to set the highlight language and line number options for
subsequent code blocks.</p>
) + "|")
else:
warnings.warn("Table cannot be rendered!")
final_table.append(separator)
for line in final_table:
result.append(line, "")
self.state.nested_parse(result, 0, node, match_titles=1)
all_nodes.extend(node.children)
return all_nodes
class LasifCLINode(nodes.General, nodes.Element):
pass
class LasifMPICLIDirective(Directive):
def run(self):
fcts = lasif_cli._get_functions()
all_nodes = []
node = nodes.section()
node.document = self.state.document
result = ViewList()
mpi_enabled = []
# Find function that have MPI.
for fct_name, fct in fcts.iteritems():
def _container_wrapper(directive, literal_node, caption):
container_node = nodes.container('', literal_block=True,
classes=['literal-block-wrapper'])
parsed = nodes.Element()
directive.state.nested_parse(StringList([caption], source=''),
directive.content_offset, parsed)
if isinstance(parsed[0], nodes.system_message): # pragma: no cover
# TODO: Figure out if this is really possible and how to produce
# it in a test case.
msg = 'Invalid caption: %s' % parsed[0].astext()
raise ValueError(msg)
assert isinstance(parsed[0], nodes.Element)
caption_node = nodes.caption(parsed[0].rawsource, '',
*parsed[0].children)
caption_node.source = literal_node.source
caption_node.line = literal_node.line
container_node += caption_node
container_node += literal_node
return container_node