git.iko.soy/typeable/pandoc
on master help sign in
Allow ibooks-specific metadata in epubs. Closes #2693.

You can now have the following fields in your YAML metadata, and it will be treated appropriately in the generated EPUB. ``` ibooks: version: 1.3.4 specified-fonts: false ipad-orientation-lock: portrait-only iphone-orientation-lock: landscape-only binding: true scroll-axis: vertical ``` This commit also fixes a regression in stylesheet paths.

commit20103ac2bcf547fa201eb5d1e79989d3466a7563 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 30 Jun 2017, 23:30 (9 years ago) parent57122f3
1 file changed+20−5
src/Text/Pandoc/Writers/EPUB.hs+20−5
src/Text/Pandoc/Writers/EPUB.hs+20−5
@@ -103,6 +103,7 @@ data EPUBMetadata = EPUBMetadata{
103103 , epubCoverImage :: Maybe String
104104 , epubStylesheets :: [FilePath]
105105 , epubPageDirection :: Maybe ProgressionDirection
106+ , epubIbooksFields :: [(String, String)]
106107 } deriving Show
107108
108109data Date = Date{
@@ -312,6 +313,7 @@ metadataFromMeta opts meta = EPUBMetadata{
312313 , epubCoverImage = coverImage
313314 , epubStylesheets = stylesheets
314315 , epubPageDirection = pageDirection
316+ , epubIbooksFields = ibooksFields
315317 }
316318 where identifiers = getIdentifier meta
317319 titles = getTitle meta
@@ -339,6 +341,10 @@ metadataFromMeta opts meta = EPUBMetadata{
339341 Just "ltr" -> Just LTR
340342 Just "rtl" -> Just RTL
341343 _ -> Nothing
344+ ibooksFields = case lookupMeta "ibooks" meta of
345+ Just (MetaMap mp)
346+ -> M.toList $ M.map metaValueToString mp
347+ _ -> []
342348
343349-- | Produce an EPUB2 file from a Pandoc document.
344350writeEPUB2 :: PandocMonad m
@@ -577,7 +583,8 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
577583 EPUB2 -> "2.0"
578584 EPUB3 -> "3.0")
579585 ,("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/")] $
581588 [ metadataElement version metadata currentTime
582589 , unode "manifest" $
583590 [ unode "item" ! [("id","ncx"), ("href","toc.ncx")
@@ -653,7 +660,7 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
653660 navMapFormatter n tit src subs = unode "navPoint" !
654661 [("id", "navPoint-" ++ show n)] $
655662 [ unode "navLabel" $ unode "text" tit
656− , unode "content" ! [("src", src)] $ ()
663+ , unode "content" ! [("src", "text/" ++ src)] $ ()
657664 ] ++ subs
658665
659666 let tpNode = unode "navPoint" ! [("id", "navPoint-0")] $
@@ -686,7 +693,8 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
686693 let navXhtmlFormatter :: Int -> String -> String -> [Element] -> Element
687694 navXhtmlFormatter n tit src subs = unode "li" !
688695 [("id", "toc-li-" ++ show n)] $
689− (unode "a" ! [("href",src)]
696+ (unode "a" ! [("href", "text/" ++
697+ src)]
690698 $ tit)
691699 : case subs of
692700 [] -> []
@@ -719,7 +727,11 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
719727 ]
720728 ]
721729 else []
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"
733+ then (k, drop 3 v)
734+ else (k, v)) vars }
723735 (Pandoc (setMeta "title"
724736 (walk removeNote $ fromList $ docTitle' meta) nullMeta)
725737 (navBlocks ++ landmarks))
@@ -761,7 +773,8 @@ metadataElement :: EPUBVersion -> EPUBMetadata -> UTCTime -> Element
761773metadataElement version md currentTime =
762774 unode "metadata" ! [("xmlns:dc","http://purl.org/dc/elements/1.1/")
763775 ,("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
765778 ++ creatorNodes ++ contributorNodes ++ subjectNodes
766779 ++ descriptionNodes ++ typeNodes ++ formatNodes
767780 ++ publisherNodes ++ sourceNodes ++ relationNodes
@@ -780,6 +793,8 @@ metadataElement version md currentTime =
780793 [] -> []
781794 (x:_) -> [dcNode "date" ! [("id","epub-date")]
782795 $ dateText x]
796+ ibooksNodes = map ibooksNode (epubIbooksFields md)
797+ ibooksNode (k, v) = unode "meta" ! [("property", "ibooks:" ++ k)] $ v
783798 languageNodes = [dcTag "language" $ epubLanguage md]
784799 creatorNodes = withIds "epub-creator" (toCreatorNode "creator") $
785800 epubCreator md