Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Design

Which decisions are confirmed, which crates read each format, what the design costs, and the choices behind it.

What is settled

The format author settled the points below on 2026-11-21. Every other detail of this section is proposed and listed again under Settled and open questions where a choice is open.

DecisionStatus
The crate converts EPUB, FB2, PDF, CBZ, DOCX, HTML, Markdown and plain text into mbookConfirmed
Mobipocket is not converted until a maintained crate reads itConfirmed
One Cargo feature per import format; every import format enabled by defaultConfirmed
Conversion from an I/O source and from a byte sliceConfirmed
Formats are read by established crates such as unpdfConfirmed
Pictures are encoded as AVIF by image with its avif feature, which uses ravif and rav1e; dependencies under BSD licenses are acceptedConfirmed
A link to an element that is not a heading keeps its target: the converter writes an anchor definition in front of it (ADR-0008, ADR-0009)Confirmed
A source without an identifier gets a UUID version 5 computed from its bytes as idConfirmed
A source without a title or a language gets Untitled and und, each with a warningConfirmed
A PDF without a text layer is converted page by page into picturesConfirmed
A comic archive has one chapter per folderConfirmed
Two kinds of source, Read and a slice; no entry point for Read + SeekConfirmed
Pictures are encoded with quality 80 and speed 6 unless the options say otherwiseConfirmed
Encoding the pictures in parallel is behind the opt-in rayon featureConfirmed on 2026-11-24
A contents entry of the source that does not lead to a heading leads to the nearest heading above its targetConfirmed
The landmarks of a source become landmarks of the book (ADR-0010)Confirmed
Streaming means a Read as the source and a Write as the sink; the book is held in memory while it is converted (Sources and memory)Confirmed

Dependencies

Every dependency was checked on 2026-11-21 against crates.io and its repository, and those of figures on 2026-11-22: the version in use is the latest one unless the notes say otherwise, and the column "Last release" shows how alive the crate is.

NeedCrateLicenseLast releaseNotes
PDF to Markdown, pictures, outline, pages as picturesunpdf 0.55, without default features, with rasterMIT2026-11Headings are found per page, by font size. Pictures are listed per page, not where they are drawn, and those under 64 pixels are left out.
EPUB package, spine, navigation, resourcesrbook 0.7, without default featuresApache-2.02026-11Reads EPUB only; Mobipocket and KF8 are announced.
HTML to Markdown (EPUB, HTML)htmd 0.6Apache-2.02026-11Writes the Markdown, with its own escaping; see below.
XML events (FictionBook, ComicInfo.xml)quick-xml 0.42 with encodingMIT2026-08
Word to Markdownundoc 0.28, with docx onlyMIT2026-11Headings need an outline level in their style. Bookmarks are not read, so links inside a document become text. Notes are plain text. A nested item is indented by two spaces a level, whatever the marker of its parent; see "Nested items of a Word list" below. Only w:start of a numbering is read, not an override of it.
ZIP archiveszip 9MIT2026-11
Dialect parsing with byte offsetsmarkdown 1.0.0MIT2025-04Already used by mbook.
Picture decoding and AVIF encodingimage 0.25 with avif, which encodes through ravif 0.13 and rav1e 0.8MIT OR Apache-2.0; BSD-3-Clause; BSD-2-Clause2026-03
Encoding pictures in parallel (rayon)rayon 1.10MIT OR Apache-2.02026-11Already in the tree: image, ravif and rav1e encode a picture on its pool.
Base64 (pictures of FictionBook and of data: addresses)base64 0.23MIT OR Apache-2.02026-08
Names of headings by GitHub's rule (Markdown)github-slugger 0.1MIT2023-06One release; a port of a frozen algorithm. Already used by mbook.
The order of the pages of a comicalphanumeric-sort 1.5MIT2026-07
Unicode NFCunicode-normalization 0.1MIT OR Apache-2.02026-10
Text encodingsencoding_rs 0.8, chardetng 1Apache-2.0 OR MIT2026-10, 2026-03
Name-based UUIDuuid 1 with v5Apache-2.0 OR MIT2026-11Already in the workspace.
Error typesthiserror 2MIT OR Apache-2.02026-09Already in the workspace.
Mermaid diagrams as SVG (export)merman 0.11, without default features, with all-diagrams, svg and layout-cytoscapeMIT OR Apache-2.02026-11Without ELK, whose layout is EPL-2.0, and without math in labels. Moved from mbook-ui on 2026-11-22.
KaTeX formulas as SVG (export)ratex-parser, ratex-layout, ratex-types, ratex-svg with embed-fonts, ratex-font, ratex-unicode-font 0.1MIT2026-11Glyphs as outlines. Moved from mbook-ui.
Glyph metrics of system fonts; the configuration of merman and the walk over a parsed formula (export)ab_glyph 0.2, serde_json 1Apache-2.0; MIT OR Apache-2.02025-09, 2026-10Moved from mbook-ui.
Rasterising a drawn figure for the writers (export)resvg 0.46 with text, system-fonts and memmap-fontsApache-2.0 OR MIT2026-110.50 is the latest release; 0.46 is the version GPUI depends on, so the application keeps one copy of resvg, usvg and fontdb. Without raster-images: a drawn figure holds no pictures.

The format author accepted dependencies under BSD-2-Clause and BSD-3-Clause on 2026-11-21: they ask only that the license text is kept. image itself contains no AV1 encoder, so its avif feature cannot be had without ravif and rav1e.

One mechanism is written in this crate: escaping text as Markdown, about forty lines in markdown.rs, used where a front end writes Markdown itself (FictionBook, plain text, comic archives). What must be escaped is a rule of the mbook dialect, not of Markdown in general: a single tilde marks strikethrough, and the parser that decides is markdown 1.0.0. The function is tested against that parser. comrak and pulldown-cmark-to-cmark write Markdown for their own parsers and dialects, and would add a second Markdown implementation to the dependency tree.

HTML is written as Markdown by htmd, including its escaping, which was checked against the dialect: a lone tilde, emphasis marks, the starts of headings, lists and quotes, brackets and literal tags all come back as text. xhtml.rs adds what Markdown output would otherwise lose, as handlers of htmd and as edits of the Markdown it wrote:

Added hereWhy htmd alone is not enough
script, style, forms and embedded objects are skippedTheir content would be written as text.
s, strike, del as ~~…~~Written as plain text.
Marks for elements with an idIdentifiers are dropped.
Footnotes of EPUBNot recognised.
A caption of a figure as the title of its pictureWritten as a separate paragraph.
A table without a header rowWritten as paragraphs; here its first row becomes the header.
pre without code, and pictures inside svgNot handled.
MarkupDropped for sub, sup, u and merged cellsDropped silently.
A line break inside a heading or a cell becomes a spaceIt would break the heading or the row.

Two properties of htmd shape that code. A handler is registered for a list of element names, there is no handler for every element, so the same handler is registered for about a hundred names, and an element with a name outside that list cannot be marked. And a handler must be 'static, so it cannot call the mappings of links and pictures that a front end supplies: handlers leave the addresses as they are, and the mappings are applied afterwards, to the Markdown, by the same code that the assembler uses.

Mobipocket is not converted (decided by the format author on 2026-11-21). A front end was written on mobi 0.8 and removed again. The crate has had no release since 2022 and depends on the unmaintained encoding 0.2. Writing against it showed more: its record access slices without checking and panics on a damaged file, its text accessor drops the last text record, and its PalmDOC decompressor shortens a match that is longer than its distance, which shifts every byte offset after it. Only its header parser could be used; cutting the records and unpacking the text had to be written here, which is a parser of a binary format in all but name. No other crate with a permissive license reads the format: boko is under the GPL, and rbook has only announced it.

The structure of FictionBook is read by this crate, as events of quick-xml (decided by the format author on 2026-11-21). The fb2 crate was used first and dropped: it has had no release since 2023, pins quick-xml 0.30, fails on a whole document for a series number such as 1.5 or for an empty body, and loses the order between the text of a section and its subsections.

Crates that were looked at and ruled out:

CrateWhy it does not fit
fb2 0.4Unmaintained since 2023; the defects above.
mobi 0.8Unmaintained since 2022; the defects above.
palmdoc-compression 0.3Would replace one of the three parts mobi gets wrong; last release 2024, about 200 recent downloads. Not evaluated.
natord 1No release since 2015; replaced by alphanumeric-sort.
ebook-rs 0.19Reads FictionBook, Mobipocket and KF8, but is three months old with 66 releases, cannot switch formats off, and always brings aes, regex, whatlang, serde_json and parking_lot. Its source was not read.
epub 2.1GPL-3.0-or-later.
html2md 0.2GPL-3.0-or-later.
boko 0.6GPL-3.0-or-later, and needs Rust 1.91.
html-to-markdown-rs 3Needs Rust 1.99.
kreuzberg 4, hayro 0.9Need Rust 1.91 and 1.92.
mdka 3.3No hook to rewrite a link or a picture; writes raw <a id> and <br>.
anytomd 1.3No EPUB, FB2 or PDF; no hook for links; brings an HTTP client by default.
pdf-extract, lopdfPlain text without headings, tables or an outline; unpdf gives all three.

Drawbacks

  • Memory is the size of the book, not of a window. The whole Book exists before the first byte is written, and for most formats the source is held as well.
  • AVIF encoding dominates the time. The pure-Rust encoder needs seconds for a large page; a comic of several hundred pages takes minutes. The rayon feature spreads the pictures over the cores; a small picture alone keeps only a few of them busy.
  • The dependency tree is large with default features: an AV1 encoder, an HTML parser, two versions of quick-xml, a PDF parser.
  • The quality of a conversion is the quality of the front-end crate. A PDF has no chapters or paragraphs of its own; what unpdf reconstructs is what the book contains.
  • A link is kept to the block, not to the word. A link to an element inside a paragraph leads to the start of that paragraph, a link to a row of a table to the table, and a contents entry that does not name a heading to the heading above its target.
  • One build per feature. The completion checks of the repository run Clippy, the tests and the documentation once for every format alone.
  • Four entry points for one operation, because Rust cannot choose between a Read and a slice by itself.

Rationale and alternatives

DecisionChosenRejectedWhy
Where formats are parsedAn established crate per formatParsers of this crate over zip and quick-xmlDecided by the format author. Less code to keep correct; the cost is memory and a larger tree.
What a front end returnsA draft in the source's terms; one assemblerEach front end builds a BookPaths, links, the dialect and pictures would be implemented once per format.
Result of a conversionA Book, then Book::writeA writer that emits resources while the source is readDecided by the format author: a Read in and a Write out is enough. The tables are the first resources of a file and describe everything after them; mbook writes only from a Book.
SourcesRead and &[u8]PathsA caller opens a file in one line; a stream has no path.
One entry point over a Source enum&[u8] is itself a Read, so a conversion from both cannot be chosen by a trait.
Sources that could seekBuffered like any ReadA third entry point for Read + SeekDecided by the format author: the API stays at two kinds of source. A caller that minds the copy maps the file into memory and passes the slice.
Finding the formatFrom the contentFrom a file extensionStreams have no names, and extensions are wrong often enough.
A disabled formatThe variant stays; Error::FormatDisabledVariants behind cfgA match on Format would change with the feature set, and the error could not say what is missing.
PicturesEncoded by this crateAn encoder supplied by the callerWorks without setup. A trait for other encoders can be added without breaking the API.
AVIF encoderrav1e, through ravif and the avif feature of image; pure Rustlibavif or libaomDecided by the format author. No C toolchain, and one crate both decodes the source pictures and encodes the result; slower than the C encoders, which are under BSD licenses as well.
Constructs that cannot be keptDropped with a warningAn errorA book without one table is more useful than no book.
Links to elements that are not headingsKept, as anchor definitions in the target chapterSent to the nearest headingDecided by the format author, who changed the format for it (ADR-0008, ADR-0009).
Missing title or languageA stand-in value and a warningAn errorThe caller can correct a Book; it cannot correct a failed conversion.
Final validationBook::check of mbookChecks of this crateOne definition of a valid book.
Export inputA borrowed BookA second set of stream and slice entry pointsA caller can export an edited in-memory book. Book::open or Book::read can load a saved one.
Export writersepub-builder, docx-rs, krilla, xmlwriter and the Markdown serializers of pulldown-cmark and pulldown-cmark-to-cmarkHand-built ZIP and PDF document packages or shelling out to a converterThe libraries handle the formats and work without an installed converter.
Nested items of a Word listBefore undoc renders the document, the level of every item in its model is set to the one whose two spaces a level reach the text of the parent item: one more level under - , two under 1. or 10. Reindenting the Markdown undoc renders; rendering the lists without undoc; leaving it to undocCommonMark nests an item only when it is indented as far as the text of its parent, and undoc indents two spaces a level, which is enough under a bullet only, so an item under a number joined the list of its parent and a bullet under a number split that list in three. In the rendered text an item cannot be told from a line of text that starts with spaces, and rendering lists here would repeat the escaping and the runs of undoc. The model is public and the level is used only for the indent. The cost is a dependence on the two spaces a level of undoc 0.28, which the tests of the importer check.
Lists in an exported Word documentWord numbering: one abstract numbering for each list of the book, with its start in the level of the list, and every paragraph of an item a paragraph of its ownParagraphs with the marker as text; one numbering for all lists, restarted with an override of the levelWith the marker as text an item had no indent, a tight nested list ran into the paragraph of its parent, and a document read back had text where the lists were. Word continues counting across the numberings of one abstract numbering unless it is overridden, and undoc does not read the override, so a list that starts at 3 would come back from 1. One numbering for each list costs a few hundred bytes of numbering.xml per list.
Landmarks in an EPUBThe writer replaces the landmarks navigation and adds to the guide in the archive epub-builder generated, rewriting those two documents with zip and copying every other entry as it isThe reftype of epub-builder; writing the EPUB package without epub-builderA reftype belongs to a whole document of the spine and takes one of 17 fixed types, so the anchor of a landmark, a second landmark of one chapter and six kinds would be lost, and epub-builder does not make its archive trait public to change the files it writes. Writing the package by hand would replace the library for one table. The cost is a second pass over the archive in memory and a dependence on the paths and the <guide> that epub-builder 0.8 writes, which the tests of the writer check.
CBZ pagesRasterize the paginated edition with unpdfExport only embedded picturesA text-only book also produces readable pages.
Encoding pictures in parallelBehind the opt-in rayon feature: the pictures the chapters show are found first, encoded on the rayon pool in runs of at most 32,000,000 declared pixels, and stored in the order of first useAlways in parallel; encoding as each chapter shows a picture, as without the feature; std::thread::scopeDecided by the format author to put it behind a feature. Measured on a 7 MB EPUB with 45 pictures (25.5 megapixels in all, the largest 1.9) on an Apple M-series processor with the NEON assembly of rav1e: 3.9 s before, 2.6 s with it on eight threads, 5.6 s and 4.3 s on four; the bytes are the same. rav1e already works on the pool of rayon, so one pool shares the cores between pictures and within one; threads of their own would compete with it. The budget keeps the memory of a run near that of one picture at the limit of max_picture_pixels; it is a constant, not an option, and was chosen without a measurement of memory. The price is a second walk over each chapter to find its pictures.
Export featureOne opt-in feature for all writersAn export switch for each format or writing enabled by defaultOne dependency setting enables every output while the import-only build keeps its dependency set and minimum Rust version.
Export picture decodingavif-decode 3 on rav1dimage with avif-native or avif-decode 1 with libaomThe feature shares the decoder with the application. avif-native links to system dav1d, and the older decoder builds libaom with CMake.
Diagrams and formulas in an exportDrawn as SVG and written as PNG picturesTheir alternative text, the earlier behaviour; SVG pictures; Mermaid fences and $…$ in MarkdownDecided by the format author on 2026-11-22: figures go out as pictures. FictionBook and many Word and EPUB readers show no SVG, and an SVG diagram depends on the fonts of the reader for its labels; PNG looks the same everywhere.
Where figures are drawnThe public figure module of this crate, used by export and by mbook-uiA private copy for export beside the one of mbook-ui; a crate of its ownDecided by the format author on 2026-11-22. One renderer, so an export looks like the reader; the cost is four public items under export. A crate of its own would be published and versioned for two users.
A figure that cannot be drawnIts alternative text, and the export goes onAn export errorRFC 0001 lets a reader show the alternative text; a book with one broken formula is still worth exporting. A picture that cannot be decoded still fails the export, as before.
The size of a figure in an exportScaled to the body text of the output, drawn at two pixels per unitThe pixels of the drawing as they areA formula drawn for 20-pixel text would stand out of a 16-pixel line, and a single pixel per unit blurs on a dense screen.

Prior art

ToolTaken from itLeft behind
Calibre ebook-convertInput plugins that produce one intermediate book; one output stageAn intermediate of XHTML and CSS
PandocReaders, one document model, writersA model that covers every construct of every format
unpdf, undoc, MarkItDownMarkdown as the result of extraction; pictures as separate resourcesRaw HTML as a fallback
mbookopen-like entry points, Limits, non-exhaustive options and errors

Settled and open questions

The questions of the first draft were settled by the format author on 2026-11-21; see What is settled. Two were settled by the implementation:

QuestionOutcome
Which crate writes Markdown for FB2 and text?None: escaping is a function of this crate, tested against markdown 1.0.0 (Dependencies).
How does this crate keep its markdown configuration equal to that of mbook?Both call markdown::ParseOptions::gfm(), and every converted book passes Book::check, which parses each chapter with the configuration of mbook.

Still proposed: the names of the public items, and every front-end crate marked so in Formats and features.

Future possibilities

  • Conversion in bounded memory: a writer in mbook that spools encoded resources to a temporary file and writes the tables last, fed by front ends that emit sections as they parse.
  • Progress and cancellation, for the minutes a large comic takes.
  • A caller-supplied picture encoder, for hardware or C encoders.
  • More formats when a suitable crate exists: Mobipocket and KF8/AZW3 (announced for rbook, which already reads EPUB here), DjVu, RTF, CBR.
  • SVG and JPEG 2000 pictures, rendered or decoded before encoding.
  • A strict mode that turns chosen warnings into errors.
  • Metadata from the front matter of a Markdown document, and pictures given to a Markdown or HTML document as data: addresses or by a caller.
  • A command-line tool on top of this crate and mbook.