Skip to content

andy840119/JupyterSharpParser

Repository files navigation

JupyterSharpParser

Build status CodeFactor NuGet NuGet NuGet

Jupyter parser written in C#

Samlpe :

var jupyterText = "[Text in jupyer document]";
JupyterDocument document = Jupyter.Parse(jupyterText);

//You can do anything in this document such as add cell
document.Cells.Add(new CodeCell
{
    ExecutionCount = 10,
    Source = new List<string>{"print(3 * 2)"}
});

Convert To Json :

// Output
var writer = new StringWriter();

// Create a HTML Renderer and setup it with the pipeline
var renderer = new JsonRenderer(writer);

// Renders Jupyter Document to Json (to the writer)
renderer.Render(document);

// Gets the rendered string
var result = writer.ToString();

Convert To Html :

// Output
var writer = new StringWriter();

// Create a HTML Renderer and setup it with the pipeline
var renderer = new HtmlRenderer(writer);

// Renders Jupyter Document to Json (to the writer)
renderer.Render(document);

// Gets the rendered string
var result = writer.ToString();

Convert To Pdf :

//Note : Due to Select.HtmlToPdf.NetCore, PDF limited to most 5 page,
//       And cannot work on other platform such as mac and linux.

// Output
using(var stream = new FileStream("fileName"))
{
    // Create a HTML Renderer and setup it with the pipeline
    var renderer = new PdfRenderer(stream);

    // Renders Jupyter Document to Json (to the writer)
    renderer.Render(document);  
}