EPUB Parsing

EPUBs are fundamentally zipped HTML, CSS, and image files. Rendering them safely requires extracting the archive in-memory and heavily sanitizing the markup before injecting it into the DOM.

Parsing Engine

We utilize a modified version of epub.js. When you load an EPUB, the engine streams the zip archive into memory, parses the content.opf file to determine spine order, and creates an isolated iframe to render chapters sequentially.

Specific Question: How are styles handled without breaking the main site layout?

EPUB stylesheets are scoped dynamically. We prepend a unique namespace class to all selectors parsed from the EPUB's internal CSS before applying them, ensuring they do not bleed into the uViewDoc interface.

EPUB Feature Support Level Notes
Flowable TextNativeAdapts to viewport resizing instantly.
Embedded FontsStrippedReplaced with system defaults to prevent memory leaks.
SVG GraphicsNativeParsed and sanitized inline.
JavaScriptDisabledAll script tags are purged during unpacking.

Common Mistakes & Constraints

  • Fixed-Layout EPUBs: We currently force all EPUBs into flowable mode. Fixed-layout comic books (EPUB3) will render, but pagination boundaries may be ignored.
  • DRM Encrypted Files: Files bought from Amazon (AZW/KFX) or Apple Books with FairPlay DRM cannot be read locally. The engine will fail gracefully with a "Decryption Required" error.

Frequently Asked Queries

Q: Does it save my reading position?
A: No. Because uViewDoc uses zero storage, closing the tab resets your position. The engine does not interact with localStorage.

Q: Why do some images look blurry?
A: If the publisher downsampled images aggressively in the EPUB to save size, we render them precisely as they exist in the archive. We apply image-rendering: pixelated where appropriate to prevent anti-aliasing blur.

Cited Statistics

As of 2023, the International Digital Publishing Forum (IDPF) reports that 85% of trade ebooks are distributed in the EPUB 3 format, making local parsing an essential tool for digital archiving.