diff options
| author | John MacFarlane <[email protected]> | 2025-01-06 09:53:34 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2025-01-06 09:53:34 -0800 |
| commit | ad105a379e3986bc60c009f017ece08d85697834 (patch) | |
| tree | 14bcb2df244fbb2717b3f6dd4343da6a255027ad /src | |
| parent | 49ecd7f0ecee803486bd9dcfbb2f1b658fd0bd59 (diff) | |
EPUB v2 writer: fix cover image.
Closes #10505. Regression from 3.6 caused by #10404.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/EPUB.hs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index af8f731a3..a29bb6aa3 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -522,7 +522,8 @@ pandocToEPUB version opts doc = do , writerWrapText = WrapAuto } -- cover page - (cpgEntry, cpicEntry) <- createCoverPage meta metadata opts' vars cssvars writeHtml plainTitle + (cpgEntry, cpicEntry, mbCoverImageName) <- + createCoverPage meta metadata opts' vars cssvars writeHtml plainTitle -- title page tpContent <- lift $ writeHtml opts'{ @@ -642,7 +643,7 @@ pandocToEPUB version opts doc = do [("xml:lang", epubLanguage metadata) | version == EPUB3] ++ [("unique-identifier","epub-id-1")] ++ [("prefix","ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/") | version == EPUB3]) $ - [ metadataElement version metadata currentTime + [ metadataElement version metadata mbCoverImageName currentTime , unode "manifest" $ [ unode "item" ! [("id","ncx"), ("href","toc.ncx") ,("media-type","application/x-dtbncx+xml")] $ () @@ -742,6 +743,7 @@ pandocToEPUB version opts doc = do -- | Function used during conversion from pandoc to EPUB to create the cover page. -- The first Entry list is for the cover while the second one is for the cover image. -- If no cover images are specified, empty lists will be returned. +-- The third value of the returned tuple is the cover image name. createCoverPage :: PandocMonad m => Meta -> EPUBMetadata @@ -750,10 +752,10 @@ createCoverPage :: PandocMonad m => -> (Bool -> Context Text) -> (WriterOptions -> Pandoc -> m B8.ByteString) -> Text - -> StateT EPUBState m ([Entry], [Entry]) + -> StateT EPUBState m ([Entry], [Entry], Maybe FilePath) createCoverPage meta metadata opts' vars cssvars writeHtml plainTitle = case epubCoverImage metadata of - Nothing -> return ([],[]) + Nothing -> return ([],[], Nothing) Just img -> do let fp = takeFileName img -- retrieve cover image file @@ -785,7 +787,7 @@ createCoverPage meta metadata opts' vars cssvars writeHtml plainTitle = coverImageEntry <- mkEntry ("media/" ++ coverImageName) imgContent - return ( [ coverEntry ], [ coverImageEntry ] ) + return ( [ coverEntry ], [ coverImageEntry ], Just coverImageName ) -- | Converts the given chapters to entries using the writeHtml function -- and the various provided options @@ -992,8 +994,9 @@ createNavEntry opts meta metadata -- Return mkEntry "nav.xhtml" navData -metadataElement :: EPUBVersion -> EPUBMetadata -> UTCTime -> Element -metadataElement version md currentTime = +metadataElement :: EPUBVersion -> EPUBMetadata -> Maybe FilePath -> UTCTime + -> Element +metadataElement version md mbCoverImage currentTime = unode "metadata" ! [("xmlns:dc","http://purl.org/dc/elements/1.1/") ,("xmlns:opf","http://www.idpf.org/2007/opf")] $ mdNodes where mdNodes = identifierNodes ++ titleNodes ++ dateNodes @@ -1048,7 +1051,7 @@ metadataElement version md currentTime = (\img -> [unode "meta" ! [(metaprop,"cover"), ("content",toId img)] $ () | version == EPUB2]) - $ epubCoverImage md + $ mbCoverImage modifiedNodes = [ unode "meta" ! [(metaprop, "dcterms:modified")] $ showDateTimeISO8601 currentTime | version == EPUB3 ] belongsToCollectionNodes = |
