DEV Community

Vikki
Vikki

Posted on

EBook with Markdown

This is an introduction.

Chapter 1

This is the first paragraph of chapter 1.

This is the second paragraph of chapter 1.

Below is a list.

  • Item One
  • Item Two
  • Item Three

Chapter 2

This is the first paragraph of chapter 2.

This is the second paragraph of chapter 2.

Chapter 3

This is the first paragraph of chapter 3.

This is the second paragraph of chapter 3.
Note that the file begins with a YAML metadata block that starts and ends with three hyphens (---). This allows you to specify EPUB metadata such as the title and author.

Converting this to EPUB is done by running pandoc.

$ pandoc example_ebook.md -t epub3 --toc -o example_ebook.epub
There are several options that need to be passed to pandoc.

example_ebook.md - This argument is the file that you are converting.
also -t epub3 - Set the output format to be EPUB v3 book.
and --toc - Include a table of contents in the output document. This will be derived from the H1 headers in the markdown.
this -o example_ebook.epub - Tell pandoc to output the conversion to the named file instead of stdout.
You can now copy the file example_ebook.epub to any device that supports the format or use one of the many software readers such as Calibre. However, if you wish to read this on a Kindle device you will need to convert it to the Mobi format.

Amazon provides a command line tool called KindleGen that can convert our EPUB file into the Mobi format. After downloading the tool just run it as shown below.

$ kindlegen example_ebook.epub
This will create a file called example_ebook.mobi that you can copy to your Kindle to read.

Top comments (0)