We want to convert a Wolfram Notebook into a jekyll markdown to use on this blog. At this point we are only converting 6 type of cells: Section, Subsection, Subsubsection, Text, Input and Output. Here is how to get all of these cells as a list:

image1.png

Processing text cells

We’ll define a single function, processCell, that will convert cells of a different type into strings. The simplest possible case is a simple text in (sub)section titles or text:

image2.png

image3.png

A little bit more complex are cases where there is some formatting inside the text, for example italic, text formatted as input, etc. We’ll define a processTextData function to deal with this:

image4.png

image5.png

image6.png

Processing inputs and outputs

To process inputs and outputs, we need to convert them into a PNG file. We’ll be using two global variables, $imageOutputDir which defines where to output files, and $imageNumber, which is a counter for the current image being output.

image7.png

Main conversion function

Now that we have defined utilities for converting individual cells, we can define a function to convert a notebook. Since out ultimate goal is do conversion with a press of a single pallette button, we want to define reasonable default values for as many required parameters as possible.

image8.png

For simplicity, we expect the very first cell to contain a title and be formatted with Section style.

image9.png

Similarly, the second cell should contain a representation of date.

image10.png

If neither of this conditions holds, we’ ll signal an error and won’ t continue the conversion. We will also copy the notebook to /assets/notebooks folder, and put the link to the source at the end of the blog post.

image11.png

Download this notebook