Skip to main content

Python 2/3 and IPython 3 compatible!

Convert IPython Notebooks to markdown (and back)

notedown is a simple tool to create IPython notebooks from markdown (and r-markdown).

notedown separates your markdown into code and not code. Code blocks (fenced or indented) go into input cells, everything else goes into markdown cells.

Usage:

notedown input.md > output.ipynb

Installation:

pip install notedown

or the latest on github:

pip install https://github.com/aaren/notedown/tarball/master

Conversion to markdown

Convert a notebook into markdown, stripping all outputs:

notedown input.ipynb --to markdown --strip > output.md

Convert a notebook into markdown, with output JSON intact:

notedown input.ipynb --to markdown > output_with_outputs.md

The outputs are placed as JSON in a code-block immediately after the corresponding input code-block. notedown understands this convention as well, so it is possible to convert this markdown-with-json back into a notebook.

This means it is possible to edit markdown, convert to notebook, play around a bit and convert back to markdown.

NB: currently, notebook and cell metadata is not preserved in the conversion.

Strip the output cells from markdown:

notedown with_output_cells.md --to markdown --strip > no_output_cells.md

Running an IPython Notebook

notedown notebook.md --run > executed_notebook.ipynb

R-markdown

You can use notedown to convert r-markdown as well. We just need to tell notedown to use knitr to convert the r-markdown. This requires that you have R installed with knitr.

Convert r-markdown into markdown:

notedown input.Rmd --to markdown --knit > output.md

Convert r-markdown into an IPython notebook:

notedown input.Rmd --knit > output.ipynb
  • --rmagic will add %load_ext rpy2.ipython at the start of the notebook, allowing you to execute code cells using the rmagic extension (requires rpy2). notedown does the appropriate %R cell magic automatically.

Magic

Fenced code blocks annotated with a language other than python are read into cells using IPython’s %% cell magic.

You can disable this with --nomagic.

  • --pre lets you add arbitrary code to the start of the notebook. e.g. notedown file.md --pre '%matplotlib inline' 'import numpy as np'

How do I put a literal code block in my markdown?

By using the --match argument. notedown defaults to converting all code-blocks into code-cells. This behaviour can be changed by giving a different argument to --match:

  • --match=all: convert all code blocks (the default)

  • --match=fenced: only convert fenced code blocks

  • --match=language: only convert fenced code blocks with ‘language’ as the syntax specifier.

  • --match=strict: only convert code blocks with Pandoc style attributes containing ‘python’ and ‘input’ as classes. i.e. code blocks must look like

    ```{.python .input}
    code
    ```

This isn’t very interactive!

You can get an interactive ipython session in vim by using vim-ipython, which allows you to connect to a running ipython kernel. You can send code from vim to ipython and get code completion from the running kernel. Try it!

Where’s my syntax highlighting?!

Try using either vim-markdown or vim-pandoc. Both are clever enough to highlight code in markdown.

Rendering outputs in markdown

This is experimental!

Convert a notebook into markdown, rendering cell outputs as native markdown elements:

notedown input.ipynb --render

This means that e.g. png outputs become ![](data-uri) images and that text is placed in the document.

Of course, you can use this in conjuntion with runipy to produce markdown-with-code-and-figures from markdown-with-code:

notedown input.md --run --render > output.md

Not a notebook in sight!

The --render flag forces the output format to markdown.

TODO

  • [x] IPython 3 support

  • [ ] Allow kernel specification

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

notedown-1.4.2.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

notedown-1.4.2-py2-none-any.whl (16.3 kB view details)

Uploaded Python 2

File details

Details for the file notedown-1.4.2.tar.gz.

File metadata

  • Download URL: notedown-1.4.2.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for notedown-1.4.2.tar.gz
Algorithm Hash digest
SHA256 e9d77c68e2fbcadd38f6eca5d8b72657c2977b6e912e241dda681a2ae0c3d7b3
MD5 95469774d2e2927184b210c66d69f85e
BLAKE2b-256 5726cd781914d55fe89e41c0a8211bbf281558867a499acf73556406927ce7cd

See more details on using hashes here.

File details

Details for the file notedown-1.4.2-py2-none-any.whl.

File metadata

File hashes

Hashes for notedown-1.4.2-py2-none-any.whl
Algorithm Hash digest
SHA256 847c0d9e5a6a77b3c508c97b690cc78c06ab2e04664c9676d8403c7cd10e35f8
MD5 6b5baa37b7036fc26ad3c6d16b679df6
BLAKE2b-256 5787b4b222d3cb30c908e1d2b1b7e742ee126bc317961e9d70a8dcd11dc7c0ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page