@@ -103,6 +103,7 @@ data EPUBMetadata = EPUBMetadata{
103 , epubCoverImage :: Maybe String
103 , epubCoverImage :: Maybe String
104 , epubStylesheets :: [FilePath]
104 , epubStylesheets :: [FilePath]
105 , epubPageDirection :: Maybe ProgressionDirection
105 , epubPageDirection :: Maybe ProgressionDirection
106+ , epubIbooksFields :: [(String, String)]
106 } deriving Show
107 } deriving Show
108data Date = Date{
109data Date = Date{
@@ -312,6 +313,7 @@ metadataFromMeta opts meta = EPUBMetadata{
312 , epubCoverImage = coverImage
313 , epubCoverImage = coverImage
313 , epubStylesheets = stylesheets
314 , epubStylesheets = stylesheets
314 , epubPageDirection = pageDirection
315 , epubPageDirection = pageDirection
316+ , epubIbooksFields = ibooksFields
316 where identifiers = getIdentifier meta
318 where identifiers = getIdentifier meta
317 titles = getTitle meta
319 titles = getTitle meta
@@ -339,6 +341,10 @@ metadataFromMeta opts meta = EPUBMetadata{
339 Just "ltr" -> Just LTR
341 Just "ltr" -> Just LTR
340 Just "rtl" -> Just RTL
342 Just "rtl" -> Just RTL
341 _ -> Nothing
343 _ -> Nothing
344+ ibooksFields = case lookupMeta "ibooks" meta of
346+ -> M.toList $ M.map metaValueToString mp
343-- | Produce an EPUB2 file from a Pandoc document.
349-- | Produce an EPUB2 file from a Pandoc document.
344writeEPUB2 :: PandocMonad m
350writeEPUB2 :: PandocMonad m
@@ -577,7 +583,8 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
577 EPUB2 -> "2.0"
583 EPUB2 -> "2.0"
578 EPUB3 -> "3.0")
584 EPUB3 -> "3.0")
579 ,("xmlns","http://www.idpf.org/2007/opf")
585 ,("xmlns","http://www.idpf.org/2007/opf")
580− ,("unique-identifier","epub-id-1")] $
586+ ,("unique-identifier","epub-id-1")
587+ ,("prefix","ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/")] $
581 [ metadataElement version metadata currentTime
588 [ metadataElement version metadata currentTime
582 , unode "manifest" $
589 , unode "manifest" $
583 [ unode "item" ! [("id","ncx"), ("href","toc.ncx")
590 [ unode "item" ! [("id","ncx"), ("href","toc.ncx")
@@ -653,7 +660,7 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
653 navMapFormatter n tit src subs = unode "navPoint" !
660 navMapFormatter n tit src subs = unode "navPoint" !
654 [("id", "navPoint-" ++ show n)] $
661 [("id", "navPoint-" ++ show n)] $
655 [ unode "navLabel" $ unode "text" tit
662 [ unode "navLabel" $ unode "text" tit
656− , unode "content" ! [("src", src)] $ ()
663+ , unode "content" ! [("src", "text/" ++ src)] $ ()
657 ] ++ subs
664 ] ++ subs
659 let tpNode = unode "navPoint" ! [("id", "navPoint-0")] $
666 let tpNode = unode "navPoint" ! [("id", "navPoint-0")] $
@@ -686,7 +693,8 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
686 let navXhtmlFormatter :: Int -> String -> String -> [Element] -> Element
693 let navXhtmlFormatter :: Int -> String -> String -> [Element] -> Element
687 navXhtmlFormatter n tit src subs = unode "li" !
694 navXhtmlFormatter n tit src subs = unode "li" !
688 [("id", "toc-li-" ++ show n)] $
695 [("id", "toc-li-" ++ show n)] $
689− (unode "a" ! [("href",src)]
696+ (unode "a" ! [("href", "text/" ++
691 : case subs of
699 : case subs of
@@ -719,7 +727,11 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
722− navData <- lift $ writeHtml opts'{ writerVariables = ("navpage","true"):vars }
730+ navData <- lift $ writeHtml opts'{ writerVariables = ("navpage","true"):
731+ -- remove the leading ../ from stylesheet paths:
732+ map (\(k,v) -> if k == "css"
723 (Pandoc (setMeta "title"
735 (Pandoc (setMeta "title"
724 (walk removeNote $ fromList $ docTitle' meta) nullMeta)
736 (walk removeNote $ fromList $ docTitle' meta) nullMeta)
725 (navBlocks ++ landmarks))
737 (navBlocks ++ landmarks))
@@ -761,7 +773,8 @@ metadataElement :: EPUBVersion -> EPUBMetadata -> UTCTime -> Element
761metadataElement version md currentTime =
773metadataElement version md currentTime =
762 unode "metadata" ! [("xmlns:dc","http://purl.org/dc/elements/1.1/")
774 unode "metadata" ! [("xmlns:dc","http://purl.org/dc/elements/1.1/")
763 ,("xmlns:opf","http://www.idpf.org/2007/opf")] $ mdNodes
775 ,("xmlns:opf","http://www.idpf.org/2007/opf")] $ mdNodes
764− where mdNodes = identifierNodes ++ titleNodes ++ dateNodes ++ languageNodes
776+ where mdNodes = identifierNodes ++ titleNodes ++ dateNodes
777+ ++ languageNodes ++ ibooksNodes
765 ++ creatorNodes ++ contributorNodes ++ subjectNodes
778 ++ creatorNodes ++ contributorNodes ++ subjectNodes
766 ++ descriptionNodes ++ typeNodes ++ formatNodes
779 ++ descriptionNodes ++ typeNodes ++ formatNodes
767 ++ publisherNodes ++ sourceNodes ++ relationNodes
780 ++ publisherNodes ++ sourceNodes ++ relationNodes
@@ -780,6 +793,8 @@ metadataElement version md currentTime =
781 (x:_) -> [dcNode "date" ! [("id","epub-date")]
794 (x:_) -> [dcNode "date" ! [("id","epub-date")]
782 $ dateText x]
795 $ dateText x]
796+ ibooksNodes = map ibooksNode (epubIbooksFields md)
797+ ibooksNode (k, v) = unode "meta" ! [("property", "ibooks:" ++ k)] $ v
783 languageNodes = [dcTag "language" $ epubLanguage md]
798 languageNodes = [dcTag "language" $ epubLanguage md]
784 creatorNodes = withIds "epub-creator" (toCreatorNode "creator") $
799 creatorNodes = withIds "epub-creator" (toCreatorNode "creator") $
785 epubCreator md
800 epubCreator md