8

Converting Markdown to Epub or Mobi

 3 years ago
source link: https://dev.to/sks147/converting-markdown-to-epub-or-mobi-32fj
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Cover image for Converting Markdown to Epub or Mobi

Converting Markdown to Epub or Mobi

Apr 26

・2 min read

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.
Video Link: https://www.youtube.com/watch?v=L4hGDPLMPcw

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
Enter fullscreen modeExit fullscreen mode
# Install pandoc
!sudo dpkg -i pandoc-2.11.3.2-1-amd64.deb
Enter fullscreen modeExit fullscreen mode
# Clone Docker CLI documentation github repository
!git clone https://github.com/docker/cli.git
Enter fullscreen modeExit fullscreen mode
# Verify the list of markdown files and contents of files
!cd cli/docs/reference/commandline && ls -la
Enter fullscreen modeExit fullscreen mode
# 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
Enter fullscreen modeExit fullscreen mode
# Move generated file to required location
!mv cli/docs/reference/commandline/docker_cli.epub ~/work/docker_cli.epub
Enter fullscreen modeExit fullscreen mode
# Install required dependencies for Calibre
!apt update -y
!apt install libgl1-mesa-glx -y
Enter fullscreen modeExit fullscreen mode
# Download and install calibre command line utility
!wget -q -O- https://download.calibre-ebook.com/linux-installer.sh | sudo sh /dev/stdin
Enter fullscreen modeExit fullscreen mode
# Convert ebook to kindle supported .mobi format
!ebook-convert docker_cli.epub docker_cli.mobi
Enter fullscreen modeExit fullscreen mode

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.

You can follow the discussion thread on Hackernews

Originally published at https://themythicalengineer.com on Apr 21, 2021.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK