Skip to content

Expose EPUB ISBNs via metadata.isbns - #2

Closed
raphi011 wants to merge 2 commits into
developfrom
feat/epub-isbn-metadata
Closed

Expose EPUB ISBNs via metadata.isbns#2
raphi011 wants to merge 2 commits into
developfrom
feat/epub-isbn-metadata

Conversation

@raphi011

@raphi011 raphi011 commented Jun 28, 2026

Copy link
Copy Markdown
Owner

Summary

The EPUB parser now exposes the publication's ISBNs through a new metadata.isbns property. A package's primary identifier is usually a UUID, so an ISBN — when present — lives in a secondary dc:identifier. EPUBMetadataParser scans every dc:identifier and collects those recognizable as ISBNs.

Detection

A dc:identifier is treated as an ISBN when it carries any of:

  • opf:scheme="ISBN" (EPUB 2)
  • an identifier-type ONIX Code List 5 refinement — 15 (ISBN-13) / 02 (ISBN-10) (EPUB 3)
  • a urn:isbn: URN value
  • Calibre's bare isbn: value prefix

Value handling

Values are returned as declared — only the scheme prefix (urn:isbn: / isbn:) and separators (hyphens, whitespace) are stripped. There is no normalization: an ISBN-10 is returned as ISBN-10, not converted to ISBN-13, and no check-digit synthesis happens, so the toolkit never invents a value the publisher didn't write.

A publication may declare more than one ISBN — the ISBN-10 and ISBN-13 of the same book, or distinct ISBNs per format — so isbns is a list, returned in document order with duplicates removed.

API

public extension Metadata {
    /// ISBNs declared by the publication, as found in the OPF.
    var isbns: [String] { ... }
}

Surfaced following the existing mediaOverlay extension pattern: the values are stashed in otherMetadata and read back through a typed accessor, so there is no change to the public Metadata type — only an additive computed property on the Shared EPUB extension.

Testing

EPUBMetadataParserTests cases + OPF fixtures covering: EPUB 2 (opf:scheme), EPUB 3 (identifier-type for both ISBN-13 and ISBN-10), urn:isbn:, Calibre's isbn: prefix, hyphen stripping, ISBN-10 returned verbatim (no conversion), multiple ISBNs in document order, duplicate-across-schemes dedup, and the no-ISBN (UUID-only) case. make format reports no changes.

Notes

  • No JavaScript bundle changes.

raphi011 and others added 2 commits June 28, 2026 10:34
The package unique-identifier is usually a UUID, so ISBNs — when present —
are secondary dc:identifier elements. EPUBMetadataParser now scans every
dc:identifier, recognizing an ISBN via opf:scheme="ISBN" (EPUB 2), an
identifier-type ONIX codelist 5 value (EPUB 3: 15/02), a urn:isbn: URN, or
Calibre's bare isbn: value prefix.

Values are returned as declared — only the scheme prefix and separators are
stripped, with no normalization (an ISBN-10 stays an ISBN-10), so the toolkit
never synthesizes a value the publisher didn't write. A publication may carry
several ISBNs (e.g. its ISBN-10 and ISBN-13, or distinct ISBNs per format), so
they are exposed as Metadata.isbns: [String], in document order with duplicates
removed. Follows the mediaOverlay extension pattern (stashed in otherMetadata;
no change to the public Metadata type).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@raphi011
raphi011 force-pushed the feat/epub-isbn-metadata branch from 487fadc to edcebe1 Compare June 28, 2026 08:34
@raphi011 raphi011 changed the title Expose EPUB ISBN via metadata.isbn Expose EPUB ISBNs via metadata.isbns Jun 28, 2026
@raphi011

Copy link
Copy Markdown
Owner Author

Superseded by the upstream PR readium#837.

@raphi011 raphi011 closed this Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant