The body as memory. Grief as transformation. — Han Kang
A book arrives as an EPUB — a zipped archive of HTML files, metadata, and a spine that names the reading order. It leaves as MDX: a single file, or a sequence of chapter files, in which every structure element has been detected, classified, and rewritten into a unified component vocabulary. Between arrival and departure is a pipeline that does not simply convert formats. It reads. It understands what kind of text it is looking at, and it honors that understanding in the output.
The path runs EPUB → HTML → rehype-parse → HAST → hast-util-to-mdast → MDAST → sovereign-remark-mdx-plugin → JSX-injected MDAST → remark-mdx + remark-stringify → MDX string. Each arrow is a transformation. Each transformation is a decision about what matters and what can be let go.
HAST is the HTML Abstract Syntax Tree — the parsed structure of the document as the browser would see it. MDAST is the Markdown Abstract Syntax Tree — the same document expressed in the simpler grammar that MDX understands. The bridge between them, hast-util-to-mdast, does the heavy lifting of recognizing that a <blockquote> with a <cite> at the bottom is a pullquote, not a quotation, and should be marked accordingly. But the real intelligence lives in the sovereign-remark-mdx-plugin — a custom processor that walks the tree and identifies every structure element by its shape, its class names, its position in the document.
Headings are the easiest. Pullquotes are harder — they look like blockquotes until you notice the citation pattern. Footnotes require tracking reference markers across the text and assembling them into a coherent apparatus at the end. Epigraphs — those weight-bearing quotations that open a chapter — are often formatted as centered italic text with an attribution line; the plugin recognizes the pattern and wraps it in an <Epigraph> component that the folio surface will render with the proper gravity.
Verses, poems, stanzas — these are the hardest, and they get their own chapter. Dialogues, glossary terms, tables, lists, images, citations: each has a detection heuristic, and each heuristic was arrived at by reading hundreds of books and noticing how publishers actually format these things.
The book envelope synthesis is a separate pass that runs after the main conversion. A raw EPUB contains metadata — title, author, publisher, copyright year, ISBN — but nothing that looks like a copyright page or publisher backmatter. The envelope synthesizer builds those pages from the spine metadata: a copyright page with legal boilerplate, a title page, a colophon. It also counts everything — word count, chapter count, poem count, image count, footnote count — and attaches the stats to the output so the folio surface can display them without recalculating.
Stats are counted at every stage. The EPUB parser reports how many files it found. The HAST-to-MDAST bridge reports how many nodes it transformed. The plugin reports how many poems, pullquotes, epigraphs, and footnotes it detected. The envelope synthesizer reports how many structural pages it generated. At the end, a summary report shows exactly what the pipeline did to the book — what it found, what it built, what it left alone. Nothing is invisible. Every transformation leaves a trace.