Example #1
0
    def read(self, contents):
        cells_rmd = self._rmd_reader.read(contents['rmd'])
        nb_html = self._html_nb_reader.read(contents['html'])
        # we need both inputs in jupyter nb format, so we can merge them.
        nb_rmd = convert(cells_rmd, to='notebook')

        nb_rmd['cells'] = _merge_consecutive_markdown_cells(nb_rmd['cells'])
        nb_html['cells'] = _merge_consecutive_markdown_cells(nb_html['cells'])

        nb_merged = self._merge_notebooks(nb_rmd, nb_html)
        validate(nb_merged)
        return nb_merged
Example #2
0
 def update_cell_type(self, cell, cell_type):
     if cell.cell_type == cell_type:
         return
     elif cell_type == 'code':
         cell.cell_type = 'code'
         cell.outputs = []
         cell.execution_count = None
         validate(cell, 'code_cell')
     elif cell_type == 'markdown':
         cell.cell_type = 'markdown'
         if 'outputs' in cell:
             del cell['outputs']
         if 'execution_count' in cell:
             del cell['execution_count']
         validate(cell, 'markdown_cell')
Example #3
0
 def update_cell_type(self, cell, cell_type):
     if cell.cell_type == cell_type:
         return
     elif cell_type == 'code':
         cell.cell_type = 'code'
         cell.outputs = []
         cell.execution_count = None
         validate(cell, 'code_cell')
     elif cell_type == 'markdown':
         cell.cell_type = 'markdown'
         if 'outputs' in cell:
             del cell['outputs']
         if 'execution_count' in cell:
             del cell['execution_count']
         validate(cell, 'markdown_cell')
Example #4
0
 def update_cell_type(self, cell, cell_type):
     if cell.cell_type == cell_type:
         return
     elif cell_type == "code":
         cell.cell_type = "code"
         cell.outputs = []
         cell.execution_count = None
         validate(cell, "code_cell")
     elif cell_type == "markdown":
         cell.cell_type = "markdown"
         if "outputs" in cell:
             del cell["outputs"]
         if "execution_count" in cell:
             del cell["execution_count"]
         validate(cell, "markdown_cell")
Example #5
0
def convert_rdf_to_notebook(args):
    infile = args.input_file

    input_file = os.path.basename(infile)
    notebook_name, extension = os.path.splitext(input_file)
    input_file_directory = os.path.dirname(infile)
    output_file_extension = 'ipynb'
    output_file = os.path.join(input_file_directory, notebook_name + "_rdf2nb." + output_file_extension)
    print("Converting RDF file {0} to notebook {1}".format(input_file,output_file))

    notebook = io.open(infile).read()
    g = Graph()
    nbrdf = g.parse(infile, format="turtle")
    nbconvert_rdf = get_notebook_cells(nbrdf)
    metadata = get_notebook_metadata(nbrdf)
    nb = nbbase.new_notebook(cells=nbconvert_rdf, metadata=metadata)
    validate_result = nbbase.validate(nb)
    with io.open(output_file, 'w', encoding='utf-8') as fout:
        nbformat.write(nb, fout, version=max(nbformat.versions))
        return nb
Example #6
0
 def contents(self):
     validate(self._nb)
     return self._nb
Example #7
0
 def contents(self):
     validate(self._nb)
     return self._nb