boko
A fast Rust library and CLI for converting between ebook formats.
Features
- Multi-format support: Read and write EPUB, KFX (Kindle Format 10), and AZW3
- Intermediate representation: Content is compiled to a semantic IR for accurate format conversion
- CSS preservation: Full CSS parsing and transformation between formats
- Metadata fidelity: Extended EPUB3 metadata (contributors, series, refinements) round-trips through KFX
- Lazy loading: Efficient random access via
ByteSourcetrait - Cross-platform: Native binaries for all platforms, plus WebAssembly for browsers
Supported Formats
| Format | Read | Write | Notes |
|---|---|---|---|
| EPUB 2/3 | ✓ | ✓ | Full EPUB3 metadata support |
| KFX | ✓ | ✓ | Kindle Format 10 with enhanced typography |
| AZW3 | ✓ | ✓ | Kindle Format 8 |
| MOBI | ✓ | - | Legacy format, read-only |
| Text | - | ✓ | Plain text export |
| Markdown | - | ✓ | Markdown export |
Installation
Requires Rust nightly (edition 2024).
CLI Usage
Show book info
# Human-readable output
# JSON output
Convert between formats
# EPUB to KFX (latest Kindle format)
# EPUB to AZW3
# KFX/AZW3/MOBI to EPUB
# Export to text or markdown
Inspect the IR
# Dump chapter structure
# Show structure without text content
# Dump a specific chapter
# Show only the style pool
Library Usage
use Book;
// Open a book (format auto-detected from extension)
let mut book = open?;
// Access metadata
println!;
println!;
// Iterate chapters
let spine: = book.spine.to_vec;
for entry in spine
// Export to another format
book.export?;
Working with the IR
Boko compiles ebook content to an intermediate representation (IR) that captures semantic structure:
use ;
// Compile HTML to IR
let html = r#"<p class="intro">Hello <em>world</em></p>"#;
let css = parse;
let chapter = compile_html?;
// Traverse the node tree
for node in &chapter.nodes
Architecture
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Import │ │ IR │ │ Export │
├─────────────┤ ├─────────────┤ ├─────────────┤
│ EPUB │────▶│ Nodes │────▶│ EPUB │
│ KFX │ │ Styles │ │ KFX │
│ AZW3 │ │ Metadata │ │ AZW3 │
│ MOBI │ │ TOC │ │ Text/MD │
└─────────────┘ └─────────────┘ └─────────────┘
The IR captures:
- Nodes: Semantic tree with elements, text, and structure
- Styles: Computed CSS properties per node
- Roles: Semantic annotations (heading, paragraph, list, etc.)
- Metadata: Title, authors, contributors, series, etc.
Metadata Support
Extended EPUB3 metadata is preserved during conversion:
dcterms:modified- Modification timestampdc:contributorwith role refinements (translator, editor, illustrator)file-asrefinements for sort orderingbelongs-to-collectionwith series position
Example output from boko info:
Title: The Great Novel
Authors: Jane Author
Language: en
Modified: 2024-01-15T12:00:00Z
Title Sort: Great Novel, The
Author Sort: Author, Jane
Contributors:
John Translator (trl) [Translator, John]
Collection: Epic Saga (series, #2)
Web App
A browser-based converter is available at zacharydenton.github.io/boko. All conversions happen locally in your browser using WebAssembly.
License
MIT