A CLI tool to split XHTML files inside an EPUB into separate "pages" using a marker (e.g., <div ... class="stl_ stl_02" ...>). Fast, interactive, and ready for npx!
This tool is designed to split EPUBs generated from PDFs using PDF24 Tools. The resulting EPUB will usually contain all content in a single page—perfect for splitting with this CLI.
Note: The table of contents (TOC) will not be generated automatically. After splitting, you should manually create or edit the TOC using Sigil, a free EPUB editor.
- 📖 Split EPUB XHTML/HTML files into individual pages
- 🔍 Choose your own marker (text/regex)
- 🗂️ Automatically updates OPF manifest and spine
- 🚀 Interactive interface powered by @clack/prompts
- ⚡ No install required—just use npx
- 🟢 Bun/Node.js compatible
No installation required! Just run:
npx split-epub@latestnpm install -g split-epub@latestThen run:
split-epub- Node.js 18+ or Bun
- An EPUB file in your working directory
Simply run:
npx split-epubThe CLI will guide you through:
- Selecting the EPUB file to split
- Choosing the marker (text/regex)
- Naming the output file
- Optionally previewing the split files (without repackaging)
- Unzips the EPUB into a temporary folder
- Finds all XHTML/HTML files and splits their content using your marker
- Creates new
.xhtmlfiles for each fragment - Updates the OPF manifest and spine
- Repackages everything into a new EPUB
- Make a backup of your original EPUB before running the script
- The script tries to update the
.opfif found. If your EPUB uses a different manifest/table of contents system, review manually - If your marker is different (spaces, single quotes, extra attributes), adjust the marker option or the regex in the code
- Does not handle advanced TOC (
nav.xhtml): you may need to review and regenerate navigation for perfect results - If your XHTML files use unusual namespaces or structures, you may need to adjust the script
- Clone the repository:
git clone https://github.com/adcuelloa/split-epub.git
cd split-epub- Install dependencies:
bun install- Run in development mode:
bun run index.ts- Build for production:
bun run build.
├── index.ts # Main CLI application
├── types.ts # TypeScript interfaces
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── README.md # This file
└── global.d.ts # Global TypeScript definitions
MIT
Created by adcuelloa
Built with ❤️ using @clack/prompts