Converting Wolfram Notebooks to Markdown
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:
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:
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:
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.
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.
For simplicity, we expect the very first cell to contain a title and be formatted with Section style.
Similarly, the second cell should contain a representation of date.
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.