Class JupyterCell

java.lang.Object
uk.ac.starlink.ttools.build.JupyterCell

public class JupyterCell extends Object
Manages export of a list of lines to the JSON format used for serialization of Jupyter notebooks (.ipynb files).

Currently only source code cells containing python are supported. The format was reverse-engineered by looking at an ipynb file saved by the Jupyter installation I happen to have on my machine.

Since:
5 Mar 2020
Author:
Mark Taylor
  • Constructor Summary

    Constructors
    Constructor
    Description
    Convenience constructor for an array of lines.
    Constructs a Jupyter code cell based on a given list of source code lines.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.json.JSONObject
    Turns this cell into a JSON object, suitable for export.
    static org.json.JSONObject
    Turns a list of cells into a JSON representation of a notebook, suitable for export to an ipynb file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • JupyterCell

      public JupyterCell(List<String> lines)
      Constructs a Jupyter code cell based on a given list of source code lines.
      Parameters:
      lines - lines of code, no trailing newlines required
    • JupyterCell

      public JupyterCell(String[] lines)
      Convenience constructor for an array of lines.
      Parameters:
      lines - lines of code, no trailing newlines required
  • Method Details

    • toJson

      public org.json.JSONObject toJson() throws org.json.JSONException
      Turns this cell into a JSON object, suitable for export.
      Returns:
      JSON representation of this cell
      Throws:
      org.json.JSONException
    • toNotebook

      public static org.json.JSONObject toNotebook(List<JupyterCell> cells) throws org.json.JSONException
      Turns a list of cells into a JSON representation of a notebook, suitable for export to an ipynb file.
      Parameters:
      cells - list of cells
      Returns:
      JSON representation of notebook
      Throws:
      org.json.JSONException