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.

workflow

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
!wget https://github.com/jgm/pandoc/releases/download/2.11.3.2/pandoc-2.11.3.2-1-amd64.deb
# Install pandoc
!sudo dpkg -i pandoc-2.11.3.2-1-amd64.deb
# Clone Docker CLI documentation github repository
!git clone https://github.com/docker/cli.git
# 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- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin
# Convert ebook to kindle supported .mobi format
!ebook-convert docker_cli.epub docker_cli.mobi

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

  • * AWS Cloudwatch Monitoring & Alerts using Bash Scripts

    * Running CPP and JS Kernel in Deepnote Jupyter Notebook

    * Yabai - Efficient window management on macOS

  • Share this:


    Comments


    Leave a Reply

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