Repository navigation
azw3: resolve kindle:embed refs inside served CSS flows - #25
Imaclean74 wants to merge 2 commits into
Conversation
Stylesheet flows are served from the FDST flow table, but the CSS content itself can reference embedded resources — @font-face src and background images are written as url(kindle:embed:XXXX[?mime=...]) by the KF8 writer. Served raw, those references dangle: no EPUB consumer can resolve a kindle: URL, so embedded fonts and CSS-referenced images silently break. rewrite_css_embed_refs maps each embed index to the discovered asset path (images/image_NNNN.ext vs fonts/font_NNNN.ext picks the right extension from discovery), falling back to a best-guess image path for indices that resolve to nothing. Round-trip test: an EPUB whose CSS references an image survives EPUB→AZW3→import with the reference pointing at a discovered, loadable asset; unit tests cover font/image/mime-suffix/quoted/fallback cases.
9cbf0cc to
078d1ef
Compare
CSS urls resolve against the stylesheet's own location, and KF8 CSS is served at styles/styleNNNN.css, so the root-relative images/... and fonts/... paths produced by rewrite_css_embed_refs resolved into styles/ and broke every CSS-referenced image and font (font_faces() resolves src the same way). Paths are now written relative to the stylesheet, e.g. ../images/image_0000.png. The round-trip test now resolves the url relative to the CSS asset, as a reading system does, instead of only checking that an asset name appears in the CSS; it fails against the previous behaviour.
|
Pushed a follow-up commit (e122548) fixing a bug in this PR.
Note on CI: the Clippy failure isn't from this PR. The runner moved to Rust 1.99, whose |
|
Opened #29 with the one-line Rust 1.99 Clippy fix. Once that lands, the red Clippy check here (and on other open PRs) should clear on a re-run. |
Fixes #26.
Problem
Reworked for 0.5.0: the original version of this PR added CSS-flow discovery and serving, which
b21f08ehas since implemented upstream — thanks! This PR is now just the remaining half.KF8 stylesheet flows are served from the FDST flow table as of 0.5.0, but they are served raw. The CSS content itself can reference embedded resources — the KF8 writer (both Amazon's tooling and boko's own
rewrite_css_references_fast) stores CSS-referenced resources asurl(kindle:embed:XXXX[?mime=...]), the same base32 numbering used forkindle:embedin chapter HTML (see the MobileRead KF8 documentation). Chapter HTML gets those references rewritten bytransform_kindle_refs, but CSS does not:@font-facesrcandbackground-imageURLs come back askindle:URLs no EPUB consumer can resolve — embedded fonts and CSS-referenced images silently break, and the output fails EPUB 3.3 resource checks.Fix
rewrite_css_embed_refsinsrc/import/azw3.rs, applied inload_asset's styles branch: each embed index maps to the discovered asset path —images/image_NNNN.extvsfonts/font_NNNN.extpicks the right prefix and extension straight from discovery — with a best-guess image path as fallback for unresolvable indices (matchingtransform_kindle_refs' behaviour in HTML).Tests
?mime=suffix, bare image ref, quoted ref, unresolvable-index fallback, and no-op on embed-free CSSazw3_roundtrip_resolves_embed_refs_inside_css: a synthetic EPUB (via the existingcommon::EpubBuilder) whose CSS references an image goes EPUB→AZW3→import; the reference must come back pointing at a discovered, loadable asset. Fails on current master withurl(kindle:embed:0001)served verbatim.cargo fmt --check,cargo clippy --lib,cargo testall pass.