How to use the runestone.common.runestonedirective.RunestoneNode function in runestone

To help you get started, we’ve selected a few runestone examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github RunestoneInteractive / RunestoneComponents / runestone / matrixeq / matrixeq.py View on Github external
if "foregroundcolor" in self.options:
            color_scheme += " color:" + self.options["foregroundcolor"].strip() + ";"

        self.options["colorscheme"] = color_scheme + '"'

        if "highlightcolor" in self.options:
            self.options["highlightcolor"] = self.options["highlightcolor"].strip()
        else:
            self.options["highlightcolor"] = "red"  # default highlight color

        return [MatrixEqNode(self.options)]


# ==========================================================================
class MatrixEqNode(nodes.General, nodes.Element, RunestoneNode):
    def __init__(self, content, **kwargs):
        """

        Arguments:
        - `self`:
        - `content`:
        """
        super(MatrixEqNode, self).__init__(name=content["name"], **kwargs)
        self.components = content


def matrixToHTML(text, nodeID, node):
    # Divide the text into a "header" and the matrix values
    parts = text.split(":")
    if len(parts) == 1:
        header = nodeID  # The generated ID from the calling function
github RunestoneInteractive / RunestoneComponents / runestone / datafile / __init__.py View on Github external
app.add_node(DataFileNode, html=(visit_df_node, depart_df_node))

    app.connect("doctree-resolved", process_datafile_nodes)
    app.connect("env-purge-doc", purge_datafiles)


TEMPLATE = u"""
<div class="runestone datafile">
<div class="datafile_caption">Data file: <code>%(divid)s</code></div>
<pre data-cols="%(cols)s" data-rows="%(rows)s" data-edit="%(edit)s" id="%(divid)s" data-component="datafile">%(filecontent)s</pre></div>
"""


class DataFileNode(nodes.General, nodes.Element, RunestoneNode):
    def __init__(self, content, **kwargs):
        """
        Arguments:
        - `self`:
        - `content`:
        """
        super(DataFileNode, self).__init__(**kwargs)
        self.df_content = content


# self for these functions is an instance of the writer class.  For example
# in html, self is sphinx.writers.html.SmartyPantsHTMLTranslator
# The node that is passed as a parameter is an instance of our node class.
def visit_df_node(self, node):
    res = TEMPLATE
    res = res % node.df_content
github RunestoneInteractive / RunestoneComponents / runestone / reveal / reveal.py View on Github external
from docutils import nodes
from docutils.parsers.rst import directives
from runestone.common.runestonedirective import RunestoneIdDirective, RunestoneNode

# add directives/javascript/css
def setup(app):
    app.add_directive("reveal", RevealDirective)

    app.add_autoversioned_javascript("reveal.js")
    app.add_autoversioned_stylesheet("reveal.css")

    app.add_node(RevealNode, html=(visit_reveal_node, depart_reveal_node))


class RevealNode(nodes.General, nodes.Element, RunestoneNode):
    def __init__(self, content, **kwargs):
        super(RevealNode, self).__init__(**kwargs)
        self.reveal_options = content


def visit_reveal_node(self, node):
    # Set options and format templates accordingly

    if "modal" in node.reveal_options:
        node.reveal_options["modal"] = "data-modal"
    else:
        node.reveal_options["modal"] = ""

    if "modaltitle" in node.reveal_options:
        temp = node.reveal_options["modaltitle"]
        node.reveal_options["modaltitle"] = """data-title=""" + '"' + temp + '"'
github RunestoneInteractive / RunestoneComponents / runestone / spreadsheet / spreadsheet.py View on Github external
app.add_autoversioned_javascript("spreadsheet.js")
    app.add_javascript("jexcel.js")
    app.add_javascript("japp.js")

    app.add_autoversioned_stylesheet("spreadsheet.css")
    app.add_stylesheet("jexcel.css")
    app.add_stylesheet("japp.css")

    app.add_node(SpreadSheetNode, html=(visit_ss_node, depart_ss_node))


# When the directive is process we will create nodes in the document tree to account
# for what we need to see on the final page.  Although we only care to render interactive
# textbooks as HTML one could, render the nodes as LaTex or many other languages.
#
class SpreadSheetNode(nodes.General, nodes.Element, RunestoneNode):
    def __init__(self, content, **kwargs):
        """

        Arguments:
        - `self`:
        - `content`:
        """
        super(SpreadSheetNode, self).__init__(**kwargs)
        self.ss_options = content


#
# The spreadsheet class implements the directive.
# When the directive is processed the run method is called.
# This allows us to handle any arguments, and then create a node or nodes to insert into the
# document tree to be rendered when the tree is written.
github RunestoneInteractive / RunestoneComponents / runestone / dragndrop / dragndrop.py View on Github external
TEMPLATE_START = """
<div class="%(divclass)s">
<ul id="%(divid)s" data-component="dragndrop">
    <span data-component="question">%(qnumber)s: %(question)s</span>
	%(feedback)s
"""

TEMPLATE_OPTION = """
    <li id="%(divid)s_drag%(dnd_label)s" data-component="draggable">%(dragText)s</li>
    <li for="%(divid)s_drag%(dnd_label)s" data-component="dropzone">%(dropText)s</li>
"""
TEMPLATE_END = """</ul></div>"""


class DragNDropNode(nodes.General, nodes.Element, RunestoneNode):
    def __init__(self, content, **kwargs):
        """
        Arguments:
        - `self`:
        - `content`:
        """
        super(DragNDropNode, self).__init__(**kwargs)
        self.dnd_options = content


# self for these functions is an instance of the writer class.  For example
# in html, self is sphinx.writers.html.SmartyPantsHTMLTranslator
# The node that is passed as a parameter is an instance of our node class.
def visit_dnd_node(self, node):
    res = TEMPLATE_START
github RunestoneInteractive / RunestoneComponents / runestone / assess / multiplechoice.py View on Github external
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .
#
__author__ = "bmiller"

from docutils import nodes
from docutils.parsers.rst import directives
from .assessbase import Assessment
from runestone.common.runestonedirective import RunestoneNode, get_node_line
from runestone.server.componentdb import addQuestionToDB, addHTMLToDB


class MChoiceNode(nodes.General, nodes.Element, RunestoneNode):
    def __init__(self, content, **kwargs):
        """

        Arguments:
        - `self`:
        - `content`:
        """
        super(MChoiceNode, self).__init__(**kwargs)
        self.mc_options = content


def visit_mc_node(self, node):

    node.delimiter = "_start__{}_".format(node.mc_options["divid"])
    self.body.append(node.delimiter)
github RunestoneInteractive / RunestoneComponents / runestone / question / question.py View on Github external
#

from docutils import nodes
from docutils.parsers.rst import directives
from runestone.common.runestonedirective import RunestoneIdDirective, RunestoneNode

__author__ = "bmiller"


def setup(app):
    app.add_directive("question", QuestionDirective)

    app.add_node(QuestionNode, html=(visit_question_node, depart_question_node))


class QuestionNode(nodes.General, nodes.Element, RunestoneNode):
    def __init__(self, content, **kwargs):
        super(QuestionNode, self).__init__(**kwargs)
        self.question_options = content


def visit_question_node(self, node):
    # Set options and format templates accordingly
    env = node.document.settings.env
    if not hasattr(env, "questioncounter"):
        env.questioncounter = 0

    if "number" in node.question_options:
        env.questioncounter = int(node.question_options["number"])
    else:
        env.questioncounter += 1
github RunestoneInteractive / RunestoneComponents / runestone / matrixeq / matrixeq.py View on Github external
# --------------------------------------------------------------------------
def process_matrixeq_nodes(app, env, docname):
    pass


# --------------------------------------------------------------------------
def purge_matrixeq(app, env, docname):
    pass


# ==========================================================================
# Inline_MatrixEq role
# ==========================================================================
# Create a role representing a matrix equation that can be included into an
# in-line paragraph.
class InlineMatrixEqNode(nodes.General, nodes.Element, RunestoneNode):
    """
:inline_matrixeq:`[a,b;c,d]`

    A inline_matrixeq role allows a matrix equation to be defined inside a
    paragraph. The syntax for the matrix equation is identical to a matrixeq
    directive. The operators in an in-line matrix equation are not executable.

    In the future it would be nice to figure out how to make the background
    color user configurable. (For some reason, inheriting the background color
    from the enclosing parent makes the brackets of the matrices render
    incorrectly.)

    The background color is hardcoded to a light yellow.
    The highlight color is hardcoded to red.
    """
github RunestoneInteractive / RunestoneComponents / runestone / external / external.py View on Github external
from html import escape  # py3
except ImportError:
    from cgi import escape  # py2

__author__ = "jczetta"
# Code template is directly from question.py at the moment, which is (c) Bradley N. Miller.
# This is intended as the basis for a potential new gradeable directive class, still potential TODO.


def setup(app):
    app.add_directive("external", ExternalDirective)

    app.add_node(ExternalNode, html=(visit_external_node, depart_external_node))


class ExternalNode(nodes.General, nodes.Element, RunestoneNode):
    def __init__(self, content, **kwargs):
        super(ExternalNode, self).__init__(**kwargs)
        self.external_options = content


def visit_external_node(self, node):
    # Set options and format templates accordingly
    # env = node.document.settings.env

    node.delimiter = "_start__{}_".format(node.external_options["divid"])

    self.body.append(node.delimiter)

    res = TEMPLATE_START % node.external_options
    self.body.append(res)
github RunestoneInteractive / RunestoneComponents / runestone / assess / multiplechoice.py View on Github external
answers_bullet_list.rawsource,
                    *answers_bullet_list.children,
                    **answers_bullet_list.attributes
                )
            )
            # Store the correct answers.
            self.options["correct"] = ",".join(correct_answers)

        # Check that a correct answer was provided.
        if not self.options.get("correct"):
            raise self.error("No correct answer specified.")
        return [mcNode]


# Define a bullet_list which contains answers (see the structure_).
class AnswersBulletList(nodes.bullet_list, RunestoneNode):
    pass


# Define a list_item which contains answers (see the structure_).
class AnswerListItem(nodes.list_item, RunestoneNode):
    pass


# Define a bullet_list which contains feedback (see the structure_).
class FeedbackBulletList(nodes.bullet_list, RunestoneNode):
    pass


# Define a list_item which contains answers (see the structure_).
class FeedbackListItem(nodes.list_item, RunestoneNode):
    pass