mbook-converter imports books into mbook and exports existing books to
other formats. Its central type, Converter, has four import entry points:
Result: an mbook file written to any Write
Result: a Book in memory
Source: any Read
convert
load
Source: a byte slice
convert_slice
load_slice
Each import format has a Cargo feature enabled by default. The optional
export feature enables all writers. A format is read by an established crate (unpdf for PDF, rbook
for EPUB, and so on); this crate adds what is a rule of mbook: which chapter
a piece of text belongs to, what a link or a picture is called after
conversion, what the Markdown dialect allows, and that every picture becomes
AVIF.
What is implemented lists, format by
format, what the crate does not do yet.
flowchart LR
src["Source<br/>any Read,<br/>or a byte slice"] --> det["Detect<br/>the format"]
det --> fe["Front end<br/>one established<br/>crate per format"]
fe --> draft["Draft<br/>metadata, Markdown,<br/>pictures, outline"]
draft --> asm["Assembler<br/>chapters, paths, links,<br/>dialect, AVIF"]
asm --> book["Book<br/>of mbook"]
book --> out["Any Write<br/>an .mbook file"]
The format is detected from the content, unless the caller names it.
The front end of that format parses the source with its crate and hands
over a draft: metadata, Markdown in source order with the source's own
names in links and pictures, the pictures, and an outline when there is
one.
The assembler is the same for every format. It cuts the text into
chapters, gives chapters and pictures their paths, re-targets links, brings
the Markdown into the dialect of RFC 0001, and encodes pictures as AVIF.
The result is a Book of mbook. convert writes it; load
returns it.
RFC 0001 describes a
packer that starts from FB2, EPUB or a folder, and
mbook leaves conversion to "crates
built on this one". Without such a crate every application that imports books
writes the same code: parse the source, produce Markdown without raw HTML,
re-encode pictures, rename every reference, build the contents.
Task
Who does it
Convert a file on disk
A command-line tool, a library manager
Convert an upload or a download without a temporary file