From 60f3e777f33623bcd6b3a98573d82f6cb2d8d978 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 19 Aug 2014 09:21:26 -0700 Subject: EPUB writer: don't use page-progression-direction in EPUB2. Also, if page-progression-direction not specified in metadata, don't include the attribute even in EPUB3; not including it is the same as including it with the value "default", as we did before. Closes #1550. --- src/Text/Pandoc/Writers/EPUB.hs | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) (limited to 'src/Text/Pandoc/Writers/EPUB.hs') diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index 2aab7701f..2df2b9087 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -94,7 +94,7 @@ data EPUBMetadata = EPUBMetadata{ , epubRights :: Maybe String , epubCoverImage :: Maybe String , epubStylesheet :: Maybe Stylesheet - , epubPageDirection :: ProgressionDirection + , epubPageDirection :: Maybe ProgressionDirection } deriving Show data Stylesheet = StylesheetPath FilePath @@ -123,7 +123,7 @@ data Title = Title{ , titleType :: Maybe String } deriving Show -data ProgressionDirection = LTR | RTL | Default deriving Show +data ProgressionDirection = LTR | RTL deriving Show dcName :: String -> QName dcName n = QName n Nothing (Just "dc") @@ -322,14 +322,11 @@ metadataFromMeta opts meta = EPUBMetadata{ stylesheet = (StylesheetContents <$> writerEpubStylesheet opts) `mplus` ((StylesheetPath . metaValueToString) <$> lookupMeta "stylesheet" meta) - pageDirection = maybe Default stringToPageDirection - (lookupMeta "page-progression-direction" meta) - stringToPageDirection (metaValueToString -> s) = - case s of - "ltr" -> LTR - "rtl" -> RTL - _ -> Default - + pageDirection = case map toLower . metaValueToString <$> + lookupMeta "page-progression-direction" meta of + Just "ltr" -> Just LTR + Just "rtl" -> Just RTL + _ -> Nothing -- | Produce an EPUB file from a Pandoc document. writeEPUB :: WriterOptions -- ^ Writer options @@ -394,11 +391,13 @@ writeEPUB opts doc@(Pandoc meta _) = do let mkFontEntry f = mkEntry (takeFileName f) `fmap` B.readFile f fontEntries <- mapM mkFontEntry $ writerEpubFonts opts' - -- set page progression direction + -- set page progression direction attribution let progressionDirection = case epubPageDirection metadata of - LTR -> "ltr" - RTL -> "rtl" - Default -> "default" + Just LTR | epub3 -> + [("page-progression-direction", "ltr")] + Just RTL | epub3 -> + [("page-progression-direction", "rtl")] + _ -> [] -- body pages @@ -519,8 +518,7 @@ writeEPUB opts doc@(Pandoc meta _) = do (pictureNode x)]) ++ map pictureNode picEntries ++ map fontNode fontEntries - , unode "spine" ! [("toc","ncx") - ,("page-progression-direction", progressionDirection)] $ + , unode "spine" ! ([("toc","ncx")] ++ progressionDirection) $ case epubCoverImage metadata of Nothing -> [] Just _ -> [ unode "itemref" ! -- cgit v1.2.3