Exploring Jupyer Notebook to write a Blog

DailyPriyab
gopy
Published in
5 min readOct 20, 2018

--

Jupyter Notebooks is a great platform for doing a quick code experiment and also recording and sharing your analysis with code snippet with others. But today I am trying to explore how we can write blogs with Jupyter Notebook.

Lets explore some of the ways in which we can use Jupyer notebook to write a blog in the following subsections

Starting Jupyter Notebook

You can start Jupyter Notebook using the following command:

jupyter notebook

Once you fire it you will get a screen like below:

Jupyter Notebook Home Screen

Next you can create a new notebook by New drop down menu and selecting Python 3 as the option to launch a notebook

Create a New Notebook

Once you have a launched a New Notebook You will get a new Notebook with a default Code Cell, you can change it to Markdown to start editing your Blog

Create a New Notebook

Native Support for Markdown

While many in the Python world prefer to write their documentation in “reStructuredText” I have liked the simplicity of and readability Markdown provides even in plain text form. I have been writing much of my Blogs and documentation in Markdown, Jupyter notebook came as fascinating surprise to me where I can mix my code with relevant reference notes which I can refer back in future.

Create a New Notebook

For a quick link of some of the basics of Markdown syntax you may refer to the below link which is a great premier on Markdown:

Markdown Basics

Jupyer Extensions

Now if you look at plain vanilla Jupyter Notebooks then it is limited by the features when writing basic markdown is concerned. But when we write Blogs we need Spell checker, Wyswing Editor to make the whole experience of writing Blogs and documentation more interactive. To this end I would suggest using two useful extensions which I found useful while researching on this topic.

Spell check errors marked in pink background
  • Jupyter Wysiwyg is another use full extension if you want to do Wysiwyg editing on a Markdown cell. My only problem while trying out this extension was that when I tried to edit in Wysiwyg mode the resultant text was in HTML. Now when I am writing in Markdown I prefer my code to be in Markdown hence I have disabled it for now but I am sure you can explore this option if you want.
Jupyter Wysiwyg Extension

To install these extensions you can use the following commands:

pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
jupyter nbextension enable spellchecker/main
pip install jupyter-wysiwyg
jupyter nbextension install --py jupyter_wysiwyg
jupyter nbextension enable jupyter_wysiwyg --py

Exporting To Markdown

Once you are done with editing your Notebook, next step is exporting Blog. Now if you have no intention of exporting your Blog you can very well share your .ipynb notebooks using github and sharing via https://nbviewer.jupyter.org/

But lets say you want post it as a Blog e.g. to Medium (this is what I use) or to Github pages, then there are few options for you.

  • From UI

From the Notebook tool bar under File->Download As you have lot of options to export your notebook in various formats e.g html, Markdown, reST, LaTeX and even as a Python script.

Download as Option
  • From Command line

You can try nbconvert utility that helps to convert a Jupyter notebook to the desired format e.g e.g pdf, html, Markdown, reST, LaTeX. You can follow the below command to convert a notebook:

jupyter nbconvert --to <output format> <input notebook>

e.g In my case I run the below command to get a Markdown file

!jupyter nbconvert --to markdown devsprint1_jupyterblog.ipynb[NbConvertApp] Converting notebook devsprint1_jupyterblog.ipynb to markdown
[NbConvertApp] Writing 4714 bytes to devsprint1_jupyterblog.md

Sharing Your Blog on Medium

Now this is a part for one of my next posts as this itself depending on what tools to use I may either use a web tool or write a python script. But for those who would like to explore further can refer to the below links:

  • Medium SDK for Python — while I have tried this SDK and it has worked for me but if you see the age of commits I am not sure if it is actively maintained.
  • Medium to Markdown — I am yet to explore this site so see if it works for you.
  • StackEdit — This is my favourite markdown editor and I actively use it for writing my Blogs and maintaining my Notes. I like its HTML preview pane, once you are done editing you can copy your HTML Preview and can also try copying it to a New Medium Blog though its a bit of manual process.
  • Gist — Finally you can host your Jupyter Notebook as a Github gist and directly embed it into a Medium post.

Additional Reference

--

--

DailyPriyab
gopy
Editor for

Data Engineering | Data Governance | Azure | Spark | Python | Manager