From cf11673d83126c177c2d029fe5c284329f9a927a Mon Sep 17 00:00:00 2001 From: Kelsey Hightower Date: Mon, 4 Jul 2011 23:39:50 -0400 Subject: EPUB writer: Add a meta element specify the cover. Some EPUB e-readers, such as the Nook, require a meta element inside the OPF metadata block to ensure the cover image is properly displayed. When generating an EPUB using the `--epub-cover-image` option, this patch adds the following meta element to the OPF metadata block in `content.opf`: --- src/Text/Pandoc/Writers/EPUB.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index fc0cb5912..00e95470a 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -134,7 +134,7 @@ writeEPUB mbStylesheet opts doc@(Pandoc meta _) = do ,("xmlns","http://www.idpf.org/2007/opf") ,("unique-identifier","BookId")] $ [ metadataElement (writerEPUBMetadata opts') - uuid lang plainTitle plainAuthors + uuid lang plainTitle plainAuthors mbCoverImage , unode "manifest" $ [ unode "item" ! [("id","ncx"), ("href","toc.ncx") ,("media-type","application/x-dtbncx+xml")] $ () @@ -209,8 +209,8 @@ writeEPUB mbStylesheet opts doc@(Pandoc meta _) = do (picEntries ++ cpicEntry ++ cpgEntry ++ chapterEntries) ) return $ fromArchive archive -metadataElement :: String -> UUID -> String -> String -> [String] -> Element -metadataElement metadataXML uuid lang title authors = +metadataElement :: String -> UUID -> String -> String -> [String] -> Maybe a -> Element +metadataElement metadataXML uuid lang title authors mbCoverImage = let userNodes = parseXML metadataXML elt = unode "metadata" ! [("xmlns:dc","http://purl.org/dc/elements/1.1/") ,("xmlns:opf","http://www.idpf.org/2007/opf")] $ @@ -225,7 +225,9 @@ metadataElement metadataXML uuid lang title authors = [ unode "dc:language" lang | not (elt `contains` "language") ] ++ [ unode "dc:identifier" ! [("id","BookId")] $ show uuid | not (elt `contains` "identifier") ] ++ - [ unode "dc:creator" ! [("opf:role","aut")] $ a | a <- authors ] + [ unode "dc:creator" ! [("opf:role","aut")] $ a | a <- authors ] ++ + [ unode "meta" ! [("name","cover"), ("content","cover-image")] $ () | + not (isNothing mbCoverImage) ] in elt{ elContent = elContent elt ++ map Elem newNodes } transformInlines :: HTMLMathMethod -- cgit v1.2.3