Package uk.ac.starlink.ttools.build
Class JupyterCell
- java.lang.Object
-
- uk.ac.starlink.ttools.build.JupyterCell
-
public class JupyterCell extends java.lang.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 JupyterCell(java.lang.String[] lines)
Convenience constructor for an array of lines.JupyterCell(java.util.List<java.lang.String> lines)
Constructs a Jupyter code cell based on a given list of source code lines.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.json.JSONObject
toJson()
Turns this cell into a JSON object, suitable for export.static org.json.JSONObject
toNotebook(java.util.List<JupyterCell> cells)
Turns a list of cells into a JSON representation of a notebook, suitable for export to an ipynb file.
-
-
-
Constructor Detail
-
JupyterCell
public JupyterCell(java.util.List<java.lang.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(java.lang.String[] lines)
Convenience constructor for an array of lines.- Parameters:
lines
- lines of code, no trailing newlines required
-
-
Method Detail
-
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(java.util.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
-
-