Allow specification of epub-cover-image in YAML metadata.

This commit is contained in:
John MacFarlane 2013-11-30 15:17:38 -08:00
parent 2f4bf9dfa4
commit 96b678d823
2 changed files with 13 additions and 10 deletions

6
README
View file

@ -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
========================

View file

@ -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 ]