Saturday, August 12, 2017

jupyter notebook cells in markdown

I would like to be able to write jupyter notebooks and other code in plain text. There are many ways to do this. "no web" with Pweave supports some nice formats. It looks like spyder-reports adds support for this as well. Markdown is a much favored report format, I think mostly because there is a lot of support for it now on github and across the web. 

Trying out an idea for allowing jupyter notebook cells to be written in markdown:

Abuse the link reference notation in markdown to store json metadata inside the parenthesis in the link reference like so:

[//]: # ({"cell_type": "markdown", "metadata":{"slideshow": {"slide_type": "slide"}}})
# test notebook 1
This notebook will have metadata attached to cells
[//]: # ({"cell_type": "markdown", "metadata":{"slideshow": {"slide_type": "skip"}, "tags": ["tag_example1"]}})
## second cell
- skip this slide
- it has a tag attached
[//]: # ({"cell_type": "code", "metadata":{"slideshow": {"slide_type": "slide"}}})
```{.python .input  n=1}
# first code cell, also a slide
print("hello first code cell")
print('seconde line of first code cell')
```
```{.json .output n=1}
[
 {
  "name": "stdout",
  "output_type": "stream",
  "text": "hello first code cell\nseconde line of first code cell\n"
 }
]
```
[//]: # ({"cell_type": "code", "metadata":{"slideshow": {"slide_type": "fragment"}}})
```{.python .input  n=2}
# second code cell, slide fragment
print("second code cell")
```
```{.json .output n=2}
[
 {
  "name": "stdout",
  "output_type": "stream",
  "text": "second code cell\n"
 }
]
```
[//]: # ({"cell_type": "markdown"})
#### another markdown cell
- item this has no metadata so may not getting
optional metadata header
- item
- item
[//]: # ({"cell_type": "code", "metadata":{"collapsed": true}})
```{.python .input}
```