@@ -1,4 +1,4 @@
1−{-# LANGUAGE PatternGuards, CPP, ScopedTypeVariables #-}
1+{-# LANGUAGE PatternGuards, CPP, ScopedTypeVariables, ViewPatterns #-}
22{-
33Copyright (C) 2010-2014 John MacFarlane <jgm@berkeley.edu>
44
@@ -94,6 +94,7 @@ data EPUBMetadata = EPUBMetadata{
9494 , epubRights :: Maybe String
9595 , epubCoverImage :: Maybe String
9696 , epubStylesheet :: Maybe Stylesheet
97+ , epubPageDirection :: ProgressionDirection
9798 } deriving Show
9899
99100data Stylesheet = StylesheetPath FilePath
@@ -122,6 +123,8 @@ data Title = Title{
122123 , titleType :: Maybe String
123124 } deriving Show
124125
126+data ProgressionDirection = LTR | RTL | Default deriving Show
127+
125128dcName :: String -> QName
126129dcName n = QName n Nothing (Just "dc")
127130
@@ -296,6 +299,7 @@ metadataFromMeta opts meta = EPUBMetadata{
296299 , epubRights = rights
297300 , epubCoverImage = coverImage
298301 , epubStylesheet = stylesheet
302+ , epubPageDirection = pageDirection
299303 }
300304 where identifiers = getIdentifier meta
301305 titles = getTitle meta
@@ -318,6 +322,14 @@ metadataFromMeta opts meta = EPUBMetadata{
318322 stylesheet = (StylesheetContents <$> writerEpubStylesheet opts) `mplus`
319323 ((StylesheetPath . metaValueToString) <$>
320324 lookupMeta "stylesheet" meta)
325+ pageDirection = maybe Default stringToPageDirection
326+ (lookupMeta "page-progression-direction" meta)
327+ stringToPageDirection (metaValueToString -> s) =
328+ case s of
329+ "ltr" -> LTR
330+ "rtl" -> RTL
331+ _ -> Default
332+
321333
322334-- | Produce an EPUB file from a Pandoc document.
323335writeEPUB :: WriterOptions -- ^ Writer options
@@ -382,6 +394,12 @@ writeEPUB opts doc@(Pandoc meta _) = do
382394 let mkFontEntry f = mkEntry (takeFileName f) `fmap` B.readFile f
383395 fontEntries <- mapM mkFontEntry $ writerEpubFonts opts'
384396
397+ -- set page progression direction
398+ let progressionDirection = case epubPageDirection metadata of
399+ LTR -> "ltr"
400+ RTL -> "rtl"
401+ Default -> "default"
402+
385403 -- body pages
386404
387405 -- add level 1 header to beginning if none there
@@ -501,7 +519,8 @@ writeEPUB opts doc@(Pandoc meta _) = do
501519 (pictureNode x)]) ++
502520 map pictureNode picEntries ++
503521 map fontNode fontEntries
504− , unode "spine" ! [("toc","ncx")] $
522+ , unode "spine" ! [("toc","ncx")
523+ ,("page-progression-direction", progressionDirection)] $
505524 case epubCoverImage metadata of
506525 Nothing -> []
507526 Just _ -> [ unode "itemref" !