Blog · EPUB

How to Convert EPUB to Markdown

Why people want a book as Markdown

Markdown keeps the structure of a text without locking it into an application. A book in Markdown can be annotated in a notes app, quoted in a document, searched with a code editor, kept under version control, or turned into a website. For study or research notes, that portability is the point.

Steps

  1. Open EPUB to Markdown and choose the book.
  2. Tick Include images if you want them. With it on, you get a ZIP with the .md file and an images folder whose links work. With it off, you get a single .md where images are replaced by their alt text.
  3. Press Convert to Markdown and read the preview.
  4. Download the file.

How elements are mapped

In the bookIn Markdown
h1 … h6# … ######
em, i*italic*
strong, b**bold**
Ordered and unordered lists, nested1. and - items, indented by two spaces per level
blockquoteLines beginning with >
pre, inline codeFenced block, backticks
Links to the web[text](address)
Links inside the bookPlain text (the targets do not exist in a single file)
Images![alt](images/n-name.png) in the ZIP; [Image: alt] otherwise
TablesRows with cells separated by |, no alignment row

Clean-up that is worth doing

Right-to-left and mixed-language books

Characters are stored exactly as in the book, in UTF-8. Direction is applied by the program that displays the file. Editors that support bidirectional text show Arabic or Hebrew paragraphs correctly; some code editors need a setting or an extension.

Markdown or plain text?

Choose TXT when the destination does not understand Markdown, for example a text-to-speech tool or a word counter. Choose Markdown when you want headings and emphasis to survive, or when you plan to publish the result.

Post-processing recipes

Add front matter for a static-site generator. Most generators read a small block at the top of the file. Add one by hand after conversion:

---
title: "The Test Book"
author: "Ada Tester"
source: epub
---

Split by chapter. Chapters in the converted file begin with a level-one heading. With a text editor that supports regular expressions, search for lines beginning with # and split there. On the command line, csplit -z book.md '/^# /' '{*}' writes one file per chapter.

Check external links. Links that point to web addresses are kept. Extract them with grep -o "](http[^)]*)" book.md and run them through a link checker if the book is a technical reference that cites online sources.

Make a table of contents. Many Markdown editors and generators build one from headings. Remove the converted “Contents” list from the front of the book so the generated one is not duplicated.

What a long book looks like in Markdown

Expect one file with thousands of lines. Editors that load the whole file may be slow above a few megabytes; splitting by chapter makes it manageable. Version control works well because the text is line-based, though long paragraphs on a single line produce large diffs. If you plan to track changes, wrap lines at a fixed width with your editor before the first commit.

Common surprises