Notedown - Markdown <=> IPython Notebook

Related tags

Markdown/YAMLnotedown
Overview

Python 2/3 and IPython 4 / Jupyter 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

Editing in the browser (new!)

You can configure IPython / Jupyter to seamlessly use markdown as its storage format. Add the following to your config file:

c.NotebookApp.contents_manager_class = 'notedown.NotedownContentsManager'

Now you can edit your markdown files in the browser, execute code, create plots - all stored in markdown!

For Jupyter, your config file is jupyter_notebook_config.py in ~/.jupyter. For IPython your config is ipython_notebook_config.py in your ipython profile (probably ~/.ipython/profile_default):

Editing in vim

There is a vim plugin that allows editing notebooks (ipynb files) directly in vim. They will be automatically converted to markdown on opening the file, and converted back to the original json format on writing.

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 (or any member of the block attributes)

  • --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!

Try editing the markdown in the IPython Notebook using the NotedownContentsManager (see above).

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

  • Python 3 support
  • unicode support
  • IPython 3 support
  • IPython 4 (Jupyter) support
  • Allow kernel specification
Owner
Aaron O'Leary
Aaron O'Leary
Rich-cli is a command line toolbox for fancy output in the terminal

Rich CLI Rich-cli is a command line toolbox for fancy output in the terminal, built with Rich. Rich-cli can syntax highlight a large number of file ty

Textualize 2.5k Jan 02, 2023
😸Awsome markdown readme for your profile or your portfolio

GitHub Profile Readme Description That's a simple and minimalist README.md for your profile Usage You can download or copy to your repository and make

0 Jul 24, 2022
Pure-python-server - A blogging platform written in pure python for developer to share their coding knowledge

Pure Python web server - PyProject A blogging platform written in pure python (n

Srikar Koushik Satya Viswanadha 10 Nov 07, 2022
An automated scanning, enumeration, and note taking tool for pentesters

EV1L J3ST3R An automated scanning, enumeration, and note taking tool Created by S1n1st3r Meant to help easily go through Hack The Box machine and TryH

14 Oct 02, 2022
A Straightforward Markdown Journal

Introducing Pepys: A straightforward markdown journal "It is rightly made for those who love to document their daily life events" - FOSSBytes Pepys is

Luke Briggs 23 Nov 12, 2022
Yuque2md - Offline download the markdown file and image from yuque

yuque2md 按照语雀知识库里的目录,导出语雀知识库中所有的markdown文档,并离线图片到本地 使用 安装 Python3.x clone 项目 下载依

JiaJianHuang 4 Oct 30, 2022
Preview GitHub README.md files locally before committing them.

Grip -- GitHub Readme Instant Preview Render local readme files before sending off to GitHub. Grip is a command-line server application written in Pyt

Joe Esposito 5.9k Jan 08, 2023
Markdown Presentations for Tech Conferences, Training, Developer Advocates, and Educators.

March 1, 2021: Service on gitpitch.com has been shutdown permanently. GitPitch 4.0 Docs Twitter About Watch the Introducing GitPitch 4.0 Video Visit t

David Russell 5.4k Jan 05, 2023
markdown2: A fast and complete implementation of Markdown in Python

Markdown is a light text markup format and a processor to convert that to HTML. The originator describes it as follows: Markdown is a text-to-HTML con

Trent Mick 2.4k Dec 30, 2022
WyPyPlus is a minimal wiki in 42 lines of Python code.

🍦 WyPyPlus: A personal wiki in 42 lines of code 🍦 WyPyPlus (pronounced "whippy plus") is a minimalist wiki server in 42 lines of code based on wypy

Leo Chen 8 Apr 07, 2022
Read a list in markdown and do something with it!

Markdown List Reader A simple tool for reading lists in markdown. Usage Begin by running the mdr.py file and input either a markdown string with the -

Esteban Garcia 3 Sep 13, 2021
Extensions for Python Markdown

PyMdown Extensions Extensions for Python Markdown. Documentation Extension documentation is found here: https://facelessuser.github.io/pymdown-extensi

Isaac Muse 685 Jan 01, 2023
A markdown extension for converting Leiden+ epigraphic text to TEI XML/HTML

LeidenMark $ pip install leidenmark A Python Markdown extension for converting Leiden+ epigraphic text to TEI XML/HTML. Inspired by the Brill plain te

André van Delft 2 Aug 04, 2021
Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed. Now in Python!

markdown-it-py Markdown parser done right. Follows the CommonMark spec for baseline parsing Configurable syntax: you can add new rules and even replac

Executable Books 398 Dec 24, 2022
Convert HTML to Markdown-formatted text.

html2text html2text is a Python script that converts a page of HTML into clean, easy-to-read plain ASCII text. Better yet, that ASCII also happens to

Alireza Savand 1.3k Dec 31, 2022
Remarkable Markdown Debian Package Fix

Remarkable debian package fix For some reason the Debian package for remarkable markdown editor has not been made to install properly on Ubuntu 20.04

Eric Seifert 37 Jan 02, 2023
Awesome Django Markdown Editor, supported for Bootstrap & Semantic-UI

martor Martor is a Markdown Editor plugin for Django, supported for Bootstrap & Semantic-UI. Features Live Preview Integrated with Ace Editor Supporte

659 Jan 04, 2023
Comprehensive Markdown plugin built for Django

Django MarkdownX Django MarkdownX is a comprehensive Markdown plugin built for Django, the renowned high-level Python web framework, with flexibility,

neutronX 740 Jan 08, 2023
CiteURL is an extensible tool that parses legal citations and makes links to websites where you can read the cited language for free.

CiteURL is an extensible tool that parses legal citations and makes links to websites where you can read the cited language for free. It can be used t

15 Dec 27, 2022
Provides syntax for Python-Markdown which allows for the inclusion of the contents of other Markdown documents.

Markdown-Include This is an extension to Python-Markdown which provides an "include" function, similar to that found in LaTeX (and also the C pre-proc

Chris MacMackin 85 Dec 30, 2022