epub3 nav support

This commit is contained in:
Marko Andjelic 2026-02-11 03:07:49 +00:00
commit 0a43a51205

View file

@ -25,7 +25,7 @@ import Data.Maybe (fromMaybe)
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import System.FilePath (normalise, takeDirectory, (</>))
import Text.HTML.Scalpel (Scraper, ScraperT, anySelector, attr, chroot, chroots, html, innerHTML, scrapeStringLike, text)
import Text.HTML.Scalpel (Scraper, ScraperT, anySelector, attr, chroot, chroots, html, innerHTML, scrapeStringLike, text, (@:), (@=))
import Types (Chapter (..), EpubAction, EpubEnv (..))
openEpub :: FilePath -> IO (Either String EpubEnv)
@ -87,6 +87,7 @@ resolveSpine = do
Right (DSpin.Spine maybeTocId refs) -> do
let lookupHref ident = DMan.mfiHref <$> find (\mi -> DMan.mfiId mi == ident) items
let maybeTocPath = lookupHref maybeTocId
let mNav = scrapeStringLike xmlStr navFinder
tocMap <- case maybeTocPath of
Nothing -> pure []
@ -156,3 +157,7 @@ chapterScraper = do
title <- chTitleScraper <|> pure "Untitled Chapter"
content <- chroot "body" (innerHTML anySelector) <|> innerHTML anySelector
pure (title, content)
-- needed for epub3 support, find the nav file
navFinder :: Scraper String FilePath
navFinder = attr "href" ("item" @: ["properties" @= "nav"])