Exemplo n.º 1
0
    def build_notebook(self):
        notebook = super().build_notebook()
        # Add a few empty cells
        notebook.cells.extend([
            nbformat.new_code_cell(""),
            nbformat.new_markdown_cell(" "),
            nbformat.new_raw_cell("\n"),
            nbformat.new_raw_cell("\t"),
        ])

        return notebook
Exemplo n.º 2
0
    def build_notebook(self):
        notebook = super(TestRegexRemove, self).build_notebook()
        # Add a few empty cells
        notebook.cells.extend([
            nbformat.new_code_cell(''),
            nbformat.new_markdown_cell(' '),
            nbformat.new_raw_cell('\n'),
            nbformat.new_raw_cell('\t'),
        ])

        return notebook
Exemplo n.º 3
0
    def build_notebook(self):
        notebook = super(TestRegexRemove, self).build_notebook()
        # Add a few empty cells
        notebook.cells.extend([
            nbformat.new_code_cell(''),
            nbformat.new_markdown_cell(' '),
            nbformat.new_raw_cell('\n'),
            nbformat.new_raw_cell('\t'),
        ])

        return notebook
Exemplo n.º 4
0
        def before_cell(n, cell_type):

            if cell_type == 'code':
                show = self.ipynb_show_solution
                hide = self.ipynb_hide_solution
                sol_class = 'jupman-sol-code'
            elif cell_type == 'markdown':
                show = self.ipynb_show_answer
                hide = self.ipynb_hide_answer
                sol_class = 'jupman-sol-question'
            else:
                warn("NO LABEL FOUND FOR cell_type %s, using default ones!" %
                     cell_type)
                show = self.ipynb_show_solution
                hide = self.ipynb_hide_solution
                sol_class = 'jupman-sol-code'

            s = """<a  class="jupman-sol jupman-sol-toggler" """
            s += """\n onclick="jupman.toggleSolution(this);" """
            s += """\n data-jupman-show="%s" data-jupman-hide="%s">%s</a>""" % (
                show, hide, show)
            s += """<div class="jupman-sol %s" style="display:none">  """ % sol_class

            ret = new_raw_cell()
            ret.metadata.format = "text/html"
            ret.source = s
            return ret
Exemplo n.º 5
0
 def __init__(self, cell_type='code', content=''):
     if cell_type == 'code':
         self._cell = new_code_cell(str(content))
     elif cell_type == 'markdown':
         self._cell = new_markdown_cell(str(content))
     elif cell_type == 'raw':
         self._cell = new_raw_cell(str(content))
     else:
         raise ValueError("Unrecognized cell type: {}".format(cell_type))
Exemplo n.º 6
0
 def after_cell():
     ret = new_raw_cell()
     ret.metadata.format = "text/html"
     ret.source = """</div>"""
     return ret
Exemplo n.º 7
0
x = np.arange(1, 10, .1)
y = np.sin(x)
plt.plot(x, y)
plt.show()
'''

cell = new_code_cell(source.strip())
notebook.cells.append(cell)
output = new_output('display_data', data={'image/png': image_base64})
cell.outputs.append(output)

####################################################################################################

# {
#   "cell_type" : "raw",
#   "metadata" : {
#     # the mime-type of the target nbconvert format.
#     # nbconvert to formats other than this will exclude this cell.
#     "format" : "mime/type"
#   },
#   "source" : "[some nbformat output text]"
# }

cell = new_raw_cell('raw ...')
notebook.cells.append(cell)

####################################################################################################

with open('test.ipynb', 'w') as fh:
    nbformat.write(notebook, fh)