diff options
author | John MacFarlane <jgm@berkeley.edu> | 2019-07-13 15:20:14 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2019-07-13 15:20:14 -0700 |
commit | 5f495eaace3ce4cf15a89b6b3cfb54df6d1658d8 (patch) | |
tree | 596e8f154d4be90a363fa42f0398e7c1bb5ce77f /src/Text/Pandoc/Writers | |
parent | 6cf5c3f6ac267c93fe7557add482307d494a8c75 (diff) | |
download | pandoc-5f495eaace3ce4cf15a89b6b3cfb54df6d1658d8.tar.gz |
EPUB writer: Use svg tag wrapper for cover image.
In addition, the code generating the image has been moved
to the template, to make it more customizable.
Those who use custom EPUB templates will need to adjust their
templates, adding the code to generate the cover image.
(Previously this was just inserted into 'body'.)
Closes #5643.
Diffstat (limited to 'src/Text/Pandoc/Writers')
-rw-r--r-- | src/Text/Pandoc/Writers/EPUB.hs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index 82b6e8221..fdcab1442 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -41,6 +41,7 @@ import qualified Text.Pandoc.Class as P import Data.Time import Text.Pandoc.Definition import Text.Pandoc.Error +import Text.Pandoc.ImageSize import Text.Pandoc.Logging import Text.Pandoc.MIME (MimeType, extensionFromMimeType, getMimeType) import Text.Pandoc.Options (EPUBVersion (..), HTMLMathMethod (..), @@ -450,14 +451,23 @@ pandocToEPUB version opts doc = do Nothing -> return ([],[]) Just img -> do let coverImage = takeFileName img + imgContent <- lift $ P.readFileLazy img + (coverImageWidth, coverImageHeight) <- + case imageSize opts' (B.toStrict imgContent) of + Right sz -> return $ sizeInPixels sz + Left err' -> (0, 0) <$ report + (CouldNotDetermineImageSize img err') cpContent <- lift $ writeHtml opts'{ writerVariables = ("coverpage","true"): ("pagetitle", escapeStringForXML plainTitle): + ("cover-image", coverImage): + ("cover-image-width", show coverImageWidth): + ("cover-image-height", + show coverImageHeight): cssvars True ++ vars } - (Pandoc meta [RawBlock (Format "html") $ "<div id=\"cover-image\">\n<img src=\"../media/" ++ coverImage ++ "\" alt=\"cover image\" />\n</div>"]) - imgContent <- lift $ P.readFileLazy img + (Pandoc meta []) coverEntry <- mkEntry "text/cover.xhtml" cpContent coverImageEntry <- mkEntry ("media/" ++ coverImage) imgContent |