Converting Markdown to Epub or Mobi

The Mythical Engineer

In this blog post, I will show you the process of combining and converting a list of markdown files into kindle supported ebook (.mobi) format.

In this example I would be converting official documentation of Docker website into an ebook for offline use.

I will use Pandoc to combine and convert the markdown (.md) files into .epub format. Then I will use Calibre to convert it to .mobi format.


You can follow the steps and modify the linux commands according to your needs.

If you don’t have a linux machine, you can use Deepnote platform to run linux commands in jupyter notebook.

Note: If you’re running this in Deepnote, you need to append “!” as prefix to each command, so that deepnote can identify it as bash command. If running in linux machine, remove “!” from all commands written below.

Here is a small video tutorial of the working script.

Steps to be followed:

# Download Pandoc executable
# Install pandoc
!sudo dpkg -i pandoc-
# Clone Docker CLI documentation github repository
!git clone
# Verify the list of markdown files and contents of files
!cd cli/docs/reference/commandline && ls -la
# Generate ebook from markdown files, *.md picks up all the files with .md as extension
!cd cli/docs/reference/commandline && pandoc -o docker_cli.epub --metadata title="Docker CLI Docs" *.md
# Move generated file to required location
!mv cli/docs/reference/commandline/docker_cli.epub ~/work/docker_cli.epub
# Install required dependencies for Calibre
!apt update -y
!apt install libgl1-mesa-glx -y
# Download and install calibre command line utility
!wget -q -O- | sudo sh /dev/stdin
# Convert ebook to kindle supported .mobi format
!ebook-convert docker_cli.epub

Now you can transfer generated .mobi file to your kindle device.

There is also a browser extension called EpubPress, which can convert any webpage into a kindle book in a single click. You can use it convert any webpage or blogs to read on Kindle.

Stay tuned for more tips and tricks <3.

#script  #productivity  #deepnote  #jupyter 

Suggested Reading

  • * How to restart Mac OS Network from Terminal

    * Running Rust Kernel in Deepnote

    * AWS Cloudwatch Monitoring & Alerts using Bash Scripts

    * Running CPP and JS Kernel in Deepnote Jupyter Notebook

    * Yabai - Efficient window management on macOS

  • Share this:


    Leave a Reply

    Your email address will not be published. Required fields are marked *