@@ -98,14 +98,10 @@ data EPUBMetadata = EPUBMetadata{
98 , epubCoverage :: Maybe String
98 , epubCoverage :: Maybe String
99 , epubRights :: Maybe String
99 , epubRights :: Maybe String
100 , epubCoverImage :: Maybe String
100 , epubCoverImage :: Maybe String
101− , epubStylesheet :: Maybe Stylesheet
101+ , epubStylesheets :: [FilePath]
102 , epubPageDirection :: Maybe ProgressionDirection
102 , epubPageDirection :: Maybe ProgressionDirection
103 } deriving Show
103 } deriving Show
105−data Stylesheet = StylesheetPath FilePath
106− | StylesheetContents String
109data Date = Date{
105data Date = Date{
110 dateText :: String
106 dateText :: String
111 , dateEvent :: Maybe String
107 , dateEvent :: Maybe String
@@ -240,6 +236,10 @@ metaValueToString (MetaBool True) = "true"
240metaValueToString (MetaBool False) = "false"
236metaValueToString (MetaBool False) = "false"
241metaValueToString _ = ""
237metaValueToString _ = ""
239+metaValueToPaths:: MetaValue -> [FilePath]
240+metaValueToPaths (MetaList xs) = map metaValueToString xs
241+metaValueToPaths x = [metaValueToString x]
243getList :: String -> Meta -> (MetaValue -> a) -> [a]
243getList :: String -> Meta -> (MetaValue -> a) -> [a]
244getList s meta handleMetaValue =
244getList s meta handleMetaValue =
245 case lookupMeta s meta of
245 case lookupMeta s meta of
@@ -307,7 +307,7 @@ metadataFromMeta opts meta = EPUBMetadata{
307 , epubCoverage = coverage
307 , epubCoverage = coverage
308 , epubRights = rights
308 , epubRights = rights
309 , epubCoverImage = coverImage
309 , epubCoverImage = coverImage
310− , epubStylesheet = stylesheet
310+ , epubStylesheets = stylesheets
311 , epubPageDirection = pageDirection
311 , epubPageDirection = pageDirection
313 where identifiers = getIdentifier meta
313 where identifiers = getIdentifier meta
@@ -328,9 +328,9 @@ metadataFromMeta opts meta = EPUBMetadata{
328 rights = metaValueToString <$> lookupMeta "rights" meta
328 rights = metaValueToString <$> lookupMeta "rights" meta
329 coverImage = lookup "epub-cover-image" (writerVariables opts) `mplus`
329 coverImage = lookup "epub-cover-image" (writerVariables opts) `mplus`
330 (metaValueToString <$> lookupMeta "cover-image" meta)
330 (metaValueToString <$> lookupMeta "cover-image" meta)
331− stylesheet = (StylesheetContents <$> writerEpubStylesheet opts) `mplus`
331+ stylesheets = maybe [] id
332− ((StylesheetPath . metaValueToString) <$>
333− lookupMeta "stylesheet" meta)
332+ (metaValueToPaths <$> lookupMeta "stylesheet" meta) ++
333+ [f | ("css",f) <- writerVariables opts]
334 pageDirection = case map toLower . metaValueToString <$>
334 pageDirection = case map toLower . metaValueToString <$>
335 lookupMeta "page-progression-direction" meta of
335 lookupMeta "page-progression-direction" meta of
336 Just "ltr" -> Just LTR
336 Just "ltr" -> Just LTR
@@ -374,10 +374,21 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
374 let writeHtml o = fmap UTF8.fromStringLazy .
374 let writeHtml o = fmap UTF8.fromStringLazy .
375 writeHtmlStringForEPUB version o
375 writeHtmlStringForEPUB version o
376 epochtime <- floor <$> lift P.getPOSIXTime
376 epochtime <- floor <$> lift P.getPOSIXTime
377+ metadata <- getEPUBMetadata opts meta
377 let mkEntry path content = toEntry path epochtime content
378 let mkEntry path content = toEntry path epochtime content
381+ stylesheets <- case epubStylesheets metadata of
382+ [] -> (\x -> [B.fromChunks [x]]) <$>
383+ P.readDataFile (writerUserDataDir opts) "epub.css"
384+ fs -> mapM P.readFileLazy fs
385+ let stylesheetEntries = zipWith
386+ (\bs n -> mkEntry ("stylesheet" ++ show n ++ ".css") bs)
387+ stylesheets [(1 :: Int)..]
378 let vars = ("epub3", if epub3 then "true" else "false")
389 let vars = ("epub3", if epub3 then "true" else "false")
379− : ("css", "stylesheet.css")
390+ : map (\e -> ("css", eRelativePath e)) stylesheetEntries
380− : writerVariables opts
391+ ++ [(x,y) | (x,y) <- writerVariables opts, x /= "css"]
381 let opts' = opts{ writerEmailObfuscation = NoObfuscation
392 let opts' = opts{ writerEmailObfuscation = NoObfuscation
382 , writerSectionDivs = True
393 , writerSectionDivs = True
383 , writerVariables = vars
394 , writerVariables = vars
@@ -386,7 +397,6 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
386 then MathML
397 then MathML
387 else writerHTMLMathMethod opts
398 else writerHTMLMathMethod opts
388 , writerWrapText = WrapAuto }
399 , writerWrapText = WrapAuto }
389− metadata <- getEPUBMetadata opts' meta
391 -- cover page
401 -- cover page
392 (cpgEntry, cpicEntry) <-
402 (cpgEntry, cpicEntry) <-
@@ -564,13 +574,14 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
564 , unode "manifest" $
574 , unode "manifest" $
565 [ unode "item" ! [("id","ncx"), ("href","toc.ncx")
575 [ unode "item" ! [("id","ncx"), ("href","toc.ncx")
566 ,("media-type","application/x-dtbncx+xml")] $ ()
576 ,("media-type","application/x-dtbncx+xml")] $ ()
567− , unode "item" ! [("id","style"), ("href","stylesheet.css")
568− ,("media-type","text/css")] $ ()
569 , unode "item" ! ([("id","nav")
577 , unode "item" ! ([("id","nav")
570 ,("href","nav.xhtml")
578 ,("href","nav.xhtml")
571 ,("media-type","application/xhtml+xml")] ++
579 ,("media-type","application/xhtml+xml")] ++
572 [("properties","nav") | epub3 ]) $ ()
580 [("properties","nav") | epub3 ]) $ ()
582+ [ (unode "item" ! [("id","style"), ("href",fp)
583+ ,("media-type","text/css")] $ ()) |
584+ fp <- map eRelativePath stylesheetEntries ] ++
574 map chapterNode (cpgEntry ++ (tpEntry : chapterEntries)) ++
585 map chapterNode (cpgEntry ++ (tpEntry : chapterEntries)) ++
575 (case cpicEntry of
586 (case cpicEntry of
@@ -725,19 +736,12 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
725 unode "option" ! [("name","specified-fonts")] $ "true"
736 unode "option" ! [("name","specified-fonts")] $ "true"
726 let appleEntry = mkEntry "META-INF/com.apple.ibooks.display-options.xml" apple
737 let appleEntry = mkEntry "META-INF/com.apple.ibooks.display-options.xml" apple
729− stylesheet <- case epubStylesheet metadata of
730− Just (StylesheetPath fp) -> UTF8.toStringLazy <$> (lift $ P.readFileLazy fp)
731− Just (StylesheetContents s) -> return s
732− Nothing -> UTF8.toString `fmap`
733− (lift $ P.readDataFile (writerUserDataDir opts) "epub.css")
734− let stylesheetEntry = mkEntry "stylesheet.css" $ UTF8.fromStringLazy stylesheet
736 -- construct archive
739 -- construct archive
737 let archive = foldr addEntryToArchive emptyArchive
740 let archive = foldr addEntryToArchive emptyArchive
738− (mimetypeEntry : containerEntry : appleEntry : stylesheetEntry : tpEntry :
741+ (mimetypeEntry : containerEntry : appleEntry : tpEntry :
739 contentsEntry : tocEntry : navEntry :
742 contentsEntry : tocEntry : navEntry :
743+ (stylesheetEntries ++ picEntries ++ cpicEntry ++
740− (picEntries ++ cpicEntry ++ cpgEntry ++ chapterEntries ++ fontEntries))
744+ cpgEntry ++ chapterEntries ++ fontEntries))
741 return $ fromArchive archive
745 return $ fromArchive archive
743metadataElement :: EPUBVersion -> EPUBMetadata -> UTCTime -> Element
747metadataElement :: EPUBVersion -> EPUBMetadata -> UTCTime -> Element