MejiroEPUB
MejiroEPUB writes EPUB 3 from PHP 8.3+. It was built for one job above all: letting a site that publishes long-form Japanese text — a web-novel site, most of all — hand its readers a whole work as an EPUB, made from the manuscript the site already stores.
$book = new Document(
new DocumentInfo(title: '吾輩は猫である', language: 'ja', author: '夏目漱石'),
writingMode: WritingMode::VERTICAL_RL,
notation: Notation::novel(),
);
foreach ($episodes as $episode) {
$book->section($episode->title, $episode->body);
}
$book->save('neko.epub');
What sets it apart
- Memory does not follow the length of the book. Each section is written into the archive the moment you give it, and forgotten. A 132-episode serial of 550,000 characters is built in about 0.1 s with a peak under 1 MB. See Core concepts.
- The notation your writers already use.
Notation::novel()reads the ruby and emphasis syntax of Japanese web-novel sites and was checked line by line against a real site's own parser.Notation::mejiro()reads MejiroPDF's syntax, so one manuscript gives both a PDF and an EPUB. See Notation. - Vertical Japanese that reading systems understand: right-to-left page order, ruby, sesame emphasis dots and upright two-digit numbers. See Vertical Japanese.
- Valid by construction. Every test publication passes EPUBCheck with warnings counted as failures.
- Safe with text you did not write. Markup is escaped, broken UTF-8 and control characters are cleaned, and only http, https and mailto become links.
What it does not do
- Read or edit existing EPUBs. It writes them.
- Fixed layout. Comics and picture books need a page-by-page layout; this library writes reflowable text.
- Choose fonts or sizes for your readers. Readers of e-books pick their own typeface and size, and the stylesheet deliberately leaves both alone.
Before you depend on it
- It is licensed under AGPLv3. Read Licensing before you build on it.
- There is no support commitment. Bug reports are welcome and read; there is no promised response time.
- Pull requests are not accepted, because the copyright has to stay with one author. Issues are open.
- The version is 0.x: a minor release may still change the API, and the release notes will say so when it does.