git.iko.soy/typeable/pandoc
on master help sign in
Allow specification of epub-cover-image in YAML metadata.
commit96b678d823b544e3da7dd8531615c52de6164cb8 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 30 Nov 2013, 15:17 (13 years ago) parent2f4bf9d
2 files changed+13−10
README+5−1 src/Text/Pandoc/Writers/EPUB.hs+8−9
README+5−1
@@ -541,7 +541,9 @@ Options affecting specific writers
541541
542542`--epub-cover-image=`*FILE*
543543: Use the specified image as the EPUB cover. It is recommended
544− that the image be less than 1000px in width and height.
544+ that the image be less than 1000px in width and height. Note that
545+ in a markdown source document you can also specify `epub-cover-image`
546+ in a YAML metadata block (see [EPUB Metadata], below).
545547
546548`--epub-metadata=`*FILE*
547549: Look in the specified XML file for metadata for the EPUB.
@@ -2818,6 +2820,8 @@ The following fields are recognized:
28182820 ~ A string value.
28192821`rights`
28202822 ~ A string value.
2823+`epub-cover-image`
2824+ ~ A string value (path to cover image).
28212825
28222826Literate Haskell support
28232827========================
src/Text/Pandoc/Writers/EPUB.hs+8−9
@@ -279,8 +279,7 @@ metadataFromMeta opts meta = EPUBMetadata{
279279 relation = metaValueToString <$> lookupMeta "relation" meta
280280 coverage = metaValueToString <$> lookupMeta "coverage" meta
281281 rights = metaValueToString <$> lookupMeta "rights" meta
282− coverImage = fmap (const "cover-image") $
283− lookup "epub-cover-image" $ writerVariables opts
282+ coverImage = lookup "epub-cover-image" (writerVariables opts)
284283
285284-- | Produce an EPUB file from a Pandoc document.
286285writeEPUB :: WriterOptions -- ^ Writer options
@@ -305,11 +304,11 @@ writeEPUB opts doc@(Pandoc meta _) = do
305304 then MathML Nothing
306305 else writerHTMLMathMethod opts
307306 , writerWrapText = False }
308− let mbCoverImage = lookup "epub-cover-image" vars
307+ metadata <- getEPUBMetadata opts' meta
309308
310309 -- cover page
311310 (cpgEntry, cpicEntry) <-
312− case mbCoverImage of
311+ case epubCoverImage metadata of
313312 Nothing -> return ([],[])
314313 Just img -> do
315314 let coverImage = "cover-image" ++ takeExtension img
@@ -421,7 +420,6 @@ writeEPUB opts doc@(Pandoc meta _) = do
421420 [("id", takeBaseName $ eRelativePath ent),
422421 ("href", eRelativePath ent),
423422 ("media-type", maybe "" id $ getMimeType $ eRelativePath ent)] $ ()
424− metadata <- getEPUBMetadata opts' meta
425423 let plainTitle = case docTitle meta of
426424 [] -> case epubTitle metadata of
427425 [] -> "UNTITLED"
@@ -452,7 +450,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
452450 map pictureNode (cpicEntry ++ picEntries) ++
453451 map fontNode fontEntries
454452 , unode "spine" ! [("toc","ncx")] $
455− case mbCoverImage of
453+ case epubCoverImage metadata of
456454 Nothing -> []
457455 Just _ -> [ unode "itemref" !
458456 [("idref", "cover"),("linear","no")] $ () ]
@@ -471,7 +469,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
471469 ("href","nav.xhtml")] $ ()
472470 ] ++
473471 [ unode "reference" !
474− [("type","cover"),("title","Cover"),("href","cover.xhtml")] $ () | mbCoverImage /= Nothing
472+ [("type","cover"),("title","Cover"),("href","cover.xhtml")] $ () | epubCoverImage metadata /= Nothing
475473 ]
476474 ]
477475 let contentsEntry = mkEntry "content.opf" contentsData
@@ -526,7 +524,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
526524 ,("content", "0")] $ ()
527525 , unode "meta" ! [("name","dtb:maxPageNumber")
528526 ,("content", "0")] $ ()
529− ] ++ case mbCoverImage of
527+ ] ++ case epubCoverImage metadata of
530528 Nothing -> []
531529 Just _ -> [unode "meta" ! [("name","cover"),
532530 ("content","cover-image")] $ ()]
@@ -623,7 +621,8 @@ metadataElement version md currentTime =
623621 coverageNodes = maybe [] (dcTag' "coverage") $ epubCoverage md
624622 rightsNodes = maybe [] (dcTag' "rights") $ epubRights md
625623 coverImageNodes = maybe []
626− (\ci -> [unode "meta" ! [("name","cover"), ("content",ci)] $ ()])
624+ (const $ [unode "meta" ! [("name","cover"),
625+ ("content","cover-image")] $ ()])
627626 $ epubCoverImage md
628627 modifiedNodes = [ unode "meta" ! [("property", "dcterms:modified")] $
629628 (showDateTimeISO8601 currentTime) | version == EPUB3 ]