Skip to main content

common/parser_tools/
epub_options.rs

1//! Book-level metadata for EPUB export.
2//!
3//! Unlike [`super::docx_options::DocxExportOptions`] (page geometry + typography — DOCX has no
4//! notion of "book metadata"), an EPUB package is built around exactly this: title, author,
5//! language, and reading direction are OPF/package-level metadata fields, not per-block
6//! formatting. There is no "plain" EPUB the way `to_docx` has docx-rs's built-in defaults — every
7//! field here lands somewhere in the generated `.epub`, so [`Default`] picks the most harmless
8//! values ("Untitled" title, empty author, `en` language, LTR) rather than leaving them unset.
9
10use serde::{Deserialize, Serialize};
11
12/// Book-level metadata for an EPUB export. Every field is required by the container format in
13/// some form, so unlike [`super::docx_options::DocxExportOptions`] there is no "no overrides"
14/// default that matches an unconfigured EPUB — [`Default`] instead picks the most reasonable
15/// placeholders.
16#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
17pub struct EpubExportOptions {
18    /// Book title, used for the package's `dc:title` and (when a chapter has no heading of its
19    /// own — the front-matter chapter, or the whole document when it has no headings at all) as
20    /// that chapter's title too.
21    pub title: String,
22    /// Author name, used for the package's `dc:creator`. Empty ⇒ no author is emitted.
23    pub author: String,
24    /// BCP-47/ISO 639-1 language code (e.g. `"en"`, `"fr"`), used for the package's `dc:language`
25    /// and every chapter XHTML document's `xml:lang`/`lang`. Empty ⇒ `"en"`.
26    pub language: String,
27    /// Right-to-left reading direction: sets the package's `page-progression-direction` to `rtl`
28    /// and adds `dir="rtl"` to every chapter's `<html>` element.
29    pub rtl: bool,
30}