aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README6
-rw-r--r--src/Text/Pandoc/Writers/EPUB.hs17
2 files changed, 13 insertions, 10 deletions
diff --git a/README b/README
index 3afbe8b0b..35194769b 100644
--- a/README
+++ b/README
@@ -541,7 +541,9 @@ Options affecting specific writers
`--epub-cover-image=`*FILE*
: Use the specified image as the EPUB cover. It is recommended
- that the image be less than 1000px in width and height.
+ that the image be less than 1000px in width and height. Note that
+ in a markdown source document you can also specify `epub-cover-image`
+ in a YAML metadata block (see [EPUB Metadata], below).
`--epub-metadata=`*FILE*
: Look in the specified XML file for metadata for the EPUB.
@@ -2818,6 +2820,8 @@ The following fields are recognized:
~ A string value.
`rights`
~ A string value.
+`epub-cover-image`
+ ~ A string value (path to cover image).
Literate Haskell support
========================
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs
index 4f1de5df0..a3b01848e 100644
--- a/src/Text/Pandoc/Writers/EPUB.hs
+++ b/src/Text/Pandoc/Writers/EPUB.hs
@@ -279,8 +279,7 @@ metadataFromMeta opts meta = EPUBMetadata{
relation = metaValueToString <$> lookupMeta "relation" meta
coverage = metaValueToString <$> lookupMeta "coverage" meta
rights = metaValueToString <$> lookupMeta "rights" meta
- coverImage = fmap (const "cover-image") $
- lookup "epub-cover-image" $ writerVariables opts
+ coverImage = lookup "epub-cover-image" (writerVariables opts)
-- | Produce an EPUB file from a Pandoc document.
writeEPUB :: WriterOptions -- ^ Writer options
@@ -305,11 +304,11 @@ writeEPUB opts doc@(Pandoc meta _) = do
then MathML Nothing
else writerHTMLMathMethod opts
, writerWrapText = False }
- let mbCoverImage = lookup "epub-cover-image" vars
+ metadata <- getEPUBMetadata opts' meta
-- cover page
(cpgEntry, cpicEntry) <-
- case mbCoverImage of
+ case epubCoverImage metadata of
Nothing -> return ([],[])
Just img -> do
let coverImage = "cover-image" ++ takeExtension img
@@ -421,7 +420,6 @@ writeEPUB opts doc@(Pandoc meta _) = do
[("id", takeBaseName $ eRelativePath ent),
("href", eRelativePath ent),
("media-type", maybe "" id $ getMimeType $ eRelativePath ent)] $ ()
- metadata <- getEPUBMetadata opts' meta
let plainTitle = case docTitle meta of
[] -> case epubTitle metadata of
[] -> "UNTITLED"
@@ -452,7 +450,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
map pictureNode (cpicEntry ++ picEntries) ++
map fontNode fontEntries
, unode "spine" ! [("toc","ncx")] $
- case mbCoverImage of
+ case epubCoverImage metadata of
Nothing -> []
Just _ -> [ unode "itemref" !
[("idref", "cover"),("linear","no")] $ () ]
@@ -471,7 +469,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
("href","nav.xhtml")] $ ()
] ++
[ unode "reference" !
- [("type","cover"),("title","Cover"),("href","cover.xhtml")] $ () | mbCoverImage /= Nothing
+ [("type","cover"),("title","Cover"),("href","cover.xhtml")] $ () | epubCoverImage metadata /= Nothing
]
]
let contentsEntry = mkEntry "content.opf" contentsData
@@ -526,7 +524,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
,("content", "0")] $ ()
, unode "meta" ! [("name","dtb:maxPageNumber")
,("content", "0")] $ ()
- ] ++ case mbCoverImage of
+ ] ++ case epubCoverImage metadata of
Nothing -> []
Just _ -> [unode "meta" ! [("name","cover"),
("content","cover-image")] $ ()]
@@ -623,7 +621,8 @@ metadataElement version md currentTime =
coverageNodes = maybe [] (dcTag' "coverage") $ epubCoverage md
rightsNodes = maybe [] (dcTag' "rights") $ epubRights md
coverImageNodes = maybe []
- (\ci -> [unode "meta" ! [("name","cover"), ("content",ci)] $ ()])
+ (const $ [unode "meta" ! [("name","cover"),
+ ("content","cover-image")] $ ()])
$ epubCoverImage md
modifiedNodes = [ unode "meta" ! [("property", "dcterms:modified")] $
(showDateTimeISO8601 currentTime) | version == EPUB3 ]