txt2epub · epub2txt — bidirectional document conversion toolkit.
Outputs EPUB 3.3 with auto-generated SVG cover.
cargo install --git https://github.com/ficbase/transmuteOr build from source:
git clone git@github.com:ficbase/transmute.git
cd transmute
cargo build --release
# optional egui desktop shell
cargo build --release --features gui --bin transmute-guiFormat is auto-detected by file extension.
# txt → epub (with auto-generated SVG cover)
transmute novel.txt novel.epub
# txt → epub (with custom cover image)
transmute novel.txt novel.epub -c cover.jpg
# epub → txt
transmute novel.epub novel.txt- EPUB 3.3 output — nav.xhtml navigation, XHTML5 content pages
- Editor project API — open, inspect, edit, and repackage EPUB resources without flattening XHTML/CSS
- Auto-generated SVG cover — dark theme with title & author
- Smart chapter detection — Arabic (
第1章), Chinese (第一章,第八十四章), parts/volumes (第一部,第X卷), Markdown (# Title) - Metadata extraction — auto-detects title (
《书名》) and author (作者:XXX) - Auto encoding detection — BOM → UTF-8 validation → GBK fallback, works with legacy Chinese txt files
- Preserves indentation — full-width spaces (
) kept intact in roundtrip
use transmute::{Book, Chapter, Metadata, write_epub_file, parse_epub_file};
// txt → epub
let book = Book {
metadata: Metadata {
title: "My Novel".into(),
author: "Author".into(),
language: "zh".into(),
..Default::default()
},
chapters: vec![Chapter {
title: "Chapter 1".into(),
body: "Once upon a time...".into(),
}],
cover: None, // auto-generates SVG
};
write_epub_file(&book, "output.epub")?;
// epub → txt
let book = parse_epub_file("input.epub")?;
println!("{} by {}", book.metadata.title, book.metadata.author);For an EPUB editor, use the project API so XHTML, CSS, images, fonts, OPF, and navigation files stay editable:
use transmute::{open_epub_project_file, write_epub_project_file};
let mut project = open_epub_project_file("input.epub")?;
let mut metadata = project.metadata.clone();
metadata.title = "Edited Title".into();
project.set_metadata(metadata)?;
let css = project.read_text_resource("OEBPS/styles/style.css")?;
project.set_text_resource("OEBPS/styles/style.css", css.replace("serif", "sans-serif"))?;
write_epub_project_file(&project, "output.epub")?;For a Tauri app that only needs the Rust EPUB core, depend on the library without default features:
transmute = { path = "../../transmute", default-features = false }Feature flags:
cli(default): builds thetransmuteCLI and enables text encoding detectiongui: builds the optionaltransmute-guiegui shell
MIT