Converter tool

EPUB to Markdown

Convert a DRM-free EPUB into Markdown, either a single file or a ZIP holding one file per chapter, with word counts and estimated tokens for every chapter. The book is read on your device and never uploaded.

Chapters follow the book's reading order (its spine). Links keep only their text and pictures become [image: alt] placeholders. Books with DRM are refused. The EPUB is unzipped and converted by this browser tab without being uploaded; its chapters and their Markdown stay in the page's memory until you reload or load another book.

Preview

Output Preview

Load an EPUB or the sample book to list its chapters and see the Markdown for the ones you select.

EPUB to Markdown

Operator: Abdulla Al Fahad. How tools are built and checked

A DRM-free ebook is one of the cleanest sources of long text you can give a language model or a search index, but the EPUB container gets in the way. Inside the file are dozens of XHTML pages, a package document, style sheets, fonts and a cover image, and an assistant that is handed the archive sees none of the reading order that makes it a book. Copying from a reading app is worse: page by page, with headers, page numbers and broken paragraphs.

EPUB to Markdown opens the archive, follows the book's own reading order and turns each chapter file into Markdown with its headings, emphasis, lists, quotations, tables and code blocks intact. The chapters are listed with their word counts and estimated tokens, so you can untick the copyright page and the index before building one Markdown file, or a ZIP with one numbered file per chapter for chunking and retrieval.

Key features

  • Chapters in spine order, each from its own XHTML file
  • Chapter list with checkboxes, word counts and estimated tokens, plus select all and none
  • Headings h1 to h6 kept at their level, with bold marks inside headings removed
  • Emphasis as *text*, strong as **text**, strikethrough as ~~text~~ and inline code in backticks
  • Nested ordered and unordered lists, including start numbers, and block quotes with >
  • Tables as pipe tables, with spanned cells filled by empty cells so columns stay aligned
  • Pre blocks as fenced code, with the language taken from a language- class when present
  • Links reduced to their text, footnote references written as [1], images as [image: alt text]
  • One Markdown file, or a ZIP of numbered chapter files, with optional YAML front matter
  • DRM-protected books detected from encryption.xml and refused

Where chapters and their titles come from

Input is one .epub of up to 100 MB, EPUB 2 or EPUB 3. The file must start with a ZIP signature and contain META-INF/container.xml, which names the package (.opf) file. From the package the tool reads the title (dc:title), the authors (dc:creator entries with no role or the aut role; editors and illustrators are dropped when an author is listed), the manifest and the spine, the list that sets the reading order.

Each XHTML or HTML file in the spine becomes one chapter. The navigation document is skipped, since it only repeats the chapter titles, and files that hold no text, such as the cover page, are left out with a note saying how many. Chapter titles come from the EPUB 3 navigation document, then the EPUB 2 toc.ncx, then the chapter's first heading. When none of the first three blocks of a chapter is a heading, its table-of-contents title is added as a level-one heading, and a chapter with no heading anywhere and no contents entry gets a fallback title such as Section 4.

Output is UTF-8 Markdown. With the YAML option on, the single file starts with a block holding title and author, and each chapter file in the ZIP gets book, author, chapter (its number) and chapter_title. Chapter files are named from the chapter number and a lower-case version of the title, such as 07-the-long-winter.md, and the numbers match the list on the page. Limits: 5,000 files in the reading order, 50 MB for any one unpacked chapter and 400 MB of unpacked text in total.

How it works

The archive is opened with JSZip. If META-INF/encryption.xml lists any encrypted chapter or other text file, the book is refused before any chapter is converted. Fonts that are only obfuscated, which many shop-bought and self-published books do legitimately, are listed in the same file but do not count as protection.

Text encoding is settled per chapter file: a UTF-16 byte-order mark decides first, then a legacy character set such as windows-1252 named in the XML declaration or a meta tag, and everything else is read as UTF-8. Each file is then parsed as XHTML; if that fails because the file is not well-formed, which happens with books assembled by hand, it is parsed again with the forgiving HTML parser so a stray   or unclosed tag does not stop the conversion.

The converter then walks the document. Scripts, styles, form controls, navigation blocks, hidden elements and page-break markers are dropped, and ruby annotations above Japanese or Chinese characters are removed so the base text reads cleanly. Soft hyphens and zero-width spaces, which ebook tools insert for line breaking, are deleted, and non-breaking spaces become plain spaces.

Runs of text with the same formatting are merged before marks are added, so two italic spans side by side give one *phrase* instead of a confusing *phrase**phrase*. A superscript inside a link, or a link marked as a note reference, becomes a bracketed reference such as [3]; any other superscript, like the th in 19th, stays as plain text.

Common use cases

  • Giving a model the full text of a public-domain novel for a close-reading exercise, without the front matter
  • Splitting a technical handbook into one Markdown file per chapter for a retrieval index
  • Checking how many tokens each chapter of a long book takes before deciding what to send
  • Moving your own self-published book into a Markdown-based writing or publishing workflow
  • Pulling the tables and code listings out of a programming ebook you own in DRM-free form

How to use this tool

  1. Check that the book is DRM-free. Files from shops that lock books to their own reading app will be refused.
  2. Pick the book with Choose file; dragging the .epub onto the panel works too. Use sample book loads a short three-chapter story about a lighthouse keeper, with a table, a quotation and an image placeholder, so the chapter list and output choices can be tried without a book of your own.
  3. Look down the chapter list. Untick front and back matter you do not want, such as the copyright page, acknowledgements or index.
  4. Choose one Markdown file or a ZIP of chapter files, and decide whether to keep the YAML block with the title and author.
  5. Compare the estimated token range for the selection with the context window you are working with.
  6. Download the result, or copy the Markdown for the selected chapters.

Example

the-tidal-island.epub (spine and two chapters, simplified)

<spine>
  <itemref idref="cover"/>   <!-- an image only -->
  <itemref idref="ch01"/>    <!-- nav title: "1. The Ferry" -->
  <itemref idref="ch02"/>
</spine>

<!-- ch01.xhtml -->
<p class="dropcap">The ferry left at <em>ten past six</em>, and Ruth was not on it.</p>

<!-- ch02.xhtml -->
<h2>2. Low Tide</h2>
<p>The causeway opened at 14:20.<a href="notes.xhtml#n4"><sup>4</sup></a></p>

the-tidal-island.md (YAML option on; cover.xhtml left out because it has no text)

---
title: "The Tidal Island"
author: "R. Mensah"
---

# 1. The Ferry

The ferry left at *ten past six*, and Ruth was not on it.

## 2. Low Tide

The causeway opened at 14:20.[4]

Tips for best results

  • Untick the index before sending a book to a model. An index is long, adds many tokens and carries no meaning without page numbers.
  • Use the ZIP when you plan to chunk the text. Each file starts with its chapter heading, and the YAML block keeps the book and chapter names attached to every chunk.
  • If a chapter shows only a few words, open it in the preview; it may be a part-title page that you can untick.
  • Footnotes usually sit in their own file at the end of the book. Keep that file selected if the [4] style references in the text should lead somewhere.
  • When the title list shows Section 3 or similar, the book has no table of contents entry and no heading for that file; it is often a dedication or an epigraph.

Edge cases to watch

Formatting set through CSS classes, which many ebooks use for italics, small capitals and verse indentation, is not carried over. Only em, i, strong, b and the other formatting tags are read.

A file that holds several chapters is listed once, under the first title the table of contents gives it, and one long chapter split across several files appears as several entries.

Pictures, including diagrams with text in them, become [image: alt] placeholders. Text inside images is not read, so fixed-layout comics and picture books produce little or nothing.

Links keep only their words. Cross-references such as "see Chapter 4" stay readable, but web addresses printed only in the link target are lost.

A table with no header row still gets its first row treated as the header, because Markdown tables require one.

The token figures are estimates. A book heavy in names, numbers or non-Latin scripts can tokenise differently from the estimate, so leave a margin.

Common errors and how to fix them

"This EPUB is DRM-protected: its encryption.xml lists encrypted chapter files, so the text cannot be read."
The chapter files are encrypted for a particular reading app and cannot be converted here; nothing is done to work around protection. Use a DRM-free edition of the book, such as one sold without protection or one you published yourself.
"This file is not an EPUB. An .epub is a ZIP package and this file does not start like one."
The file is another ebook format with an .epub name, or a PDF. MOBI, AZW3 and PDF books need converting to EPUB with an ebook manager before this tool can read them.
"This ZIP has no META-INF/container.xml, so it is not a readable EPUB."
Every EPUB has this file, and it is missing here, so the archive is a different kind of ZIP or a damaged book. Download the book again or re-export it from the program that made it.
"No chapter in this EPUB contains text."
The book stores its pages as pictures, which is common for comics, children's books and some textbooks. There is no text for the converter to extract; this tool does not run text recognition on images.
"This EPUB is larger than the 100 MB limit."
Large EPUBs are almost always full of high-resolution images, which the Markdown would replace with placeholders anyway. Remove or shrink the images with an EPUB editor, or split the book, then convert the smaller file.

Best practices

  • Keep the YAML block on when the Markdown will be stored or indexed, so the book and author travel with the text.
  • Name the downloaded file after the edition you converted, since two editions of the same book can differ in chapters and notes.
  • Read the first and last chapters in the preview; front and back matter is where unwanted text most often hides.
  • Respect the book's licence. Converting a file changes its format, not the terms under which you may share or reuse the text.

How chapter titles are chosen

The table of contents is the most reliable source, because it is the title the publisher chose for that file. The tool reads the EPUB 3 navigation document first and falls back to toc.ncx in older books. A file that is not in the table of contents is named after its first heading, then after the title in its head element when that differs from the book title, and as Section N when nothing else is available.

The chosen title is also the heading added to a chapter that does not open with one. A chapter whose own heading appears within its first three blocks, for example after an epigraph, keeps its own heading and gets nothing added, so headings are not doubled.

Single file or chapter ZIP

One Markdown file suits pasting into a conversation or reading the whole book in an editor. The chapters follow each other in reading order with a blank line between them, and the copy button always copies this form.

The ZIP suits retrieval systems and anything that processes text in pieces. Files are numbered by the chapter's position in the list, padded to at least two digits so they sort correctly, and a deselected chapter simply leaves a gap in the numbering rather than shifting the files after it.

  • 07-the-long-winter.md: chapter 7, with the title in the file name
  • chapter: 7 and chapter_title: "The Long Winter" in the YAML block when it is on
  • The book title and author repeated in every file's YAML block

Frequently asked questions

Why is the navigation document missing from the output?

It is the book's clickable table of contents, so converting it would only repeat every chapter title as a list. The titles are used for the chapter headings and file names instead.

Are footnotes kept?

The note text is kept wherever the book puts it, usually a notes file at the end or the bottom of each chapter. References in the text become bracketed numbers such as [12]; the jump link itself is not kept.

Can I give the Markdown or the chapter ZIP to an AI assistant?

Pasting the Markdown works wherever you can type, as long as the selected chapters fit the model's context window, which is what the per-chapter token figures help you judge. Whether a service takes .md files or ZIP archives as attachments is described in its own help pages and changes over time, so read them for the assistant you use before planning around uploads.

Is the book uploaded anywhere?

No. The EPUB is read from your disk through the File API, unzipped with JSZip and converted with DOMParser inside this tab. The page then keeps the book's title and authors, the chapter list with each chapter's Markdown, and your selection in the tab's memory, and a reload or a new book clears them. Each download reaches the browser through a short-lived object URL, which the page revokes as soon as the save has begun.