@@ -1,4 +1,4 @@
1−{-# LANGUAGE PatternGuards, CPP, ScopedTypeVariables #-}
1+{-# LANGUAGE PatternGuards, CPP, ScopedTypeVariables, ViewPatterns #-}
3Copyright (C) 2010-2014 John MacFarlane <jgm@berkeley.edu>
3Copyright (C) 2010-2014 John MacFarlane <jgm@berkeley.edu>
@@ -94,6 +94,7 @@ data EPUBMetadata = EPUBMetadata{
94 , epubRights :: Maybe String
94 , epubRights :: Maybe String
95 , epubCoverImage :: Maybe String
95 , epubCoverImage :: Maybe String
96 , epubStylesheet :: Maybe Stylesheet
96 , epubStylesheet :: Maybe Stylesheet
97+ , epubPageDirection :: ProgressionDirection
97 } deriving Show
98 } deriving Show
99data Stylesheet = StylesheetPath FilePath
100data Stylesheet = StylesheetPath FilePath
@@ -122,6 +123,8 @@ data Title = Title{
122 , titleType :: Maybe String
123 , titleType :: Maybe String
123 } deriving Show
124 } deriving Show
126+data ProgressionDirection = LTR | RTL | Default deriving Show
125dcName :: String -> QName
128dcName :: String -> QName
126dcName n = QName n Nothing (Just "dc")
129dcName n = QName n Nothing (Just "dc")
@@ -296,6 +299,7 @@ metadataFromMeta opts meta = EPUBMetadata{
296 , epubRights = rights
299 , epubRights = rights
297 , epubCoverImage = coverImage
300 , epubCoverImage = coverImage
298 , epubStylesheet = stylesheet
301 , epubStylesheet = stylesheet
302+ , epubPageDirection = pageDirection
300 where identifiers = getIdentifier meta
304 where identifiers = getIdentifier meta
301 titles = getTitle meta
305 titles = getTitle meta
@@ -318,6 +322,14 @@ metadataFromMeta opts meta = EPUBMetadata{
318 stylesheet = (StylesheetContents <$> writerEpubStylesheet opts) `mplus`
322 stylesheet = (StylesheetContents <$> writerEpubStylesheet opts) `mplus`
319 ((StylesheetPath . metaValueToString) <$>
323 ((StylesheetPath . metaValueToString) <$>
320 lookupMeta "stylesheet" meta)
324 lookupMeta "stylesheet" meta)
325+ pageDirection = maybe Default stringToPageDirection
326+ (lookupMeta "page-progression-direction" meta)
327+ stringToPageDirection (metaValueToString -> s) =
322-- | Produce an EPUB file from a Pandoc document.
334-- | Produce an EPUB file from a Pandoc document.
323writeEPUB :: WriterOptions -- ^ Writer options
335writeEPUB :: WriterOptions -- ^ Writer options
@@ -382,6 +394,12 @@ writeEPUB opts doc@(Pandoc meta _) = do
382 let mkFontEntry f = mkEntry (takeFileName f) `fmap` B.readFile f
394 let mkFontEntry f = mkEntry (takeFileName f) `fmap` B.readFile f
383 fontEntries <- mapM mkFontEntry $ writerEpubFonts opts'
395 fontEntries <- mapM mkFontEntry $ writerEpubFonts opts'
397+ -- set page progression direction
398+ let progressionDirection = case epubPageDirection metadata of
401+ Default -> "default"
385 -- body pages
403 -- body pages
387 -- add level 1 header to beginning if none there
405 -- add level 1 header to beginning if none there
@@ -501,7 +519,8 @@ writeEPUB opts doc@(Pandoc meta _) = do
501 (pictureNode x)]) ++
519 (pictureNode x)]) ++
502 map pictureNode picEntries ++
520 map pictureNode picEntries ++
503 map fontNode fontEntries
521 map fontNode fontEntries
504− , unode "spine" ! [("toc","ncx")] $
522+ , unode "spine" ! [("toc","ncx")
523+ ,("page-progression-direction", progressionDirection)] $
505 case epubCoverImage metadata of
524 case epubCoverImage metadata of
506 Nothing -> []
525 Nothing -> []
507 Just _ -> [ unode "itemref" !
526 Just _ -> [ unode "itemref" !