Exemple #1
0
 def kernel(self):
     """
     The first cell contains a small info text and sets the global octave mode.
     """
     cell = '''\
     %auto
     # This cell automatically evaluates on startup -- or run it manually if it didn't evaluate.
     # Here, it starts the Jupyter octave kernel and sets it as the default mode for this worksheet.
     %default_mode octave'''
     self.write(SagewsCell(input=textwrap.dedent(cell)).convert())
Exemple #2
0
 def kernel(self):
     """
     The first cell contains a small info text and defines the global jupyter mode,
     based on the kernel name in the ipynb file!
     """
     spec = self.nb['metadata']
     name = spec['kernelspec']['name']
     cell = '''\
     %auto
     # This cell automatically evaluates on startup -- or run it manually if it didn't evaluate.
     # Here, it initializes the Jupyter kernel with the specified name and sets it as the default mode for this worksheet.
     jupyter_kernel = jupyter("{}")  # run "jupyter?" for more information.
     %default_mode jupyter_kernel'''.format(name)
     self.write(SagewsCell(input=textwrap.dedent(cell)).convert())
Exemple #3
0
    def body(self):
        """
        Converting all cells of the ipynb as the body of the sagews document.

        see http://nbformat.readthedocs.io/en/latest/format_description.html
        """

        for cell in self.nb.cells:
            ct = cell['cell_type']
            source = cell.get('source', None)
            outputs = cell.get('outputs', [])

            if ct == 'markdown':
                self.write(SagewsCell(md=source).convert())

            elif ct == 'code':
                self.write(SagewsCell(input=source, outputs=outputs).convert())

            elif ct == 'raw':
                self.write(SagewsCell(input=source).convert())

            else:
                print("ERROR: cell type '%s' not recognized:\n%s" %
                      (ct, json.dumps(cell, indent=2)))
Exemple #4
0
 def body(self):
     """
     Convert input to body of the sagews document.
     """
     fhead = "# {}\n".format(self.infile)
     self.write(SagewsCell(input=fhead + self.m).convert())