@@ -98,14 +98,10 @@ data EPUBMetadata = EPUBMetadata{
9898 , epubCoverage :: Maybe String
9999 , epubRights :: Maybe String
100100 , epubCoverImage :: Maybe String
101− , epubStylesheet :: Maybe Stylesheet
101+ , epubStylesheets :: [FilePath]
102102 , epubPageDirection :: Maybe ProgressionDirection
103103 } deriving Show
104104
105−data Stylesheet = StylesheetPath FilePath
106− | StylesheetContents String
107− deriving Show
108−
109105data Date = Date{
110106 dateText :: String
111107 , dateEvent :: Maybe String
@@ -240,6 +236,10 @@ metaValueToString (MetaBool True) = "true"
240236metaValueToString (MetaBool False) = "false"
241237metaValueToString _ = ""
242238
239+metaValueToPaths:: MetaValue -> [FilePath]
240+metaValueToPaths (MetaList xs) = map metaValueToString xs
241+metaValueToPaths x = [metaValueToString x]
242+
243243getList :: String -> Meta -> (MetaValue -> a) -> [a]
244244getList s meta handleMetaValue =
245245 case lookupMeta s meta of
@@ -307,7 +307,7 @@ metadataFromMeta opts meta = EPUBMetadata{
307307 , epubCoverage = coverage
308308 , epubRights = rights
309309 , epubCoverImage = coverImage
310− , epubStylesheet = stylesheet
310+ , epubStylesheets = stylesheets
311311 , epubPageDirection = pageDirection
312312 }
313313 where identifiers = getIdentifier meta
@@ -328,9 +328,9 @@ metadataFromMeta opts meta = EPUBMetadata{
328328 rights = metaValueToString <$> lookupMeta "rights" meta
329329 coverImage = lookup "epub-cover-image" (writerVariables opts) `mplus`
330330 (metaValueToString <$> lookupMeta "cover-image" meta)
331− stylesheet = (StylesheetContents <$> writerEpubStylesheet opts) `mplus`
332− ((StylesheetPath . metaValueToString) <$>
333− lookupMeta "stylesheet" meta)
331+ stylesheets = maybe [] id
332+ (metaValueToPaths <$> lookupMeta "stylesheet" meta) ++
333+ [f | ("css",f) <- writerVariables opts]
334334 pageDirection = case map toLower . metaValueToString <$>
335335 lookupMeta "page-progression-direction" meta of
336336 Just "ltr" -> Just LTR
@@ -374,10 +374,21 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
374374 let writeHtml o = fmap UTF8.fromStringLazy .
375375 writeHtmlStringForEPUB version o
376376 epochtime <- floor <$> lift P.getPOSIXTime
377+ metadata <- getEPUBMetadata opts meta
377378 let mkEntry path content = toEntry path epochtime content
379+
380+ -- stylesheet
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)..]
388+
378389 let vars = ("epub3", if epub3 then "true" else "false")
379− : ("css", "stylesheet.css")
380− : writerVariables opts
390+ : map (\e -> ("css", eRelativePath e)) stylesheetEntries
391+ ++ [(x,y) | (x,y) <- writerVariables opts, x /= "css"]
381392 let opts' = opts{ writerEmailObfuscation = NoObfuscation
382393 , writerSectionDivs = True
383394 , writerVariables = vars
@@ -386,7 +397,6 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
386397 then MathML
387398 else writerHTMLMathMethod opts
388399 , writerWrapText = WrapAuto }
389− metadata <- getEPUBMetadata opts' meta
390400
391401 -- cover page
392402 (cpgEntry, cpicEntry) <-
@@ -564,13 +574,14 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
564574 , unode "manifest" $
565575 [ unode "item" ! [("id","ncx"), ("href","toc.ncx")
566576 ,("media-type","application/x-dtbncx+xml")] $ ()
567− , unode "item" ! [("id","style"), ("href","stylesheet.css")
568− ,("media-type","text/css")] $ ()
569577 , unode "item" ! ([("id","nav")
570578 ,("href","nav.xhtml")
571579 ,("media-type","application/xhtml+xml")] ++
572580 [("properties","nav") | epub3 ]) $ ()
573581 ] ++
582+ [ (unode "item" ! [("id","style"), ("href",fp)
583+ ,("media-type","text/css")] $ ()) |
584+ fp <- map eRelativePath stylesheetEntries ] ++
574585 map chapterNode (cpgEntry ++ (tpEntry : chapterEntries)) ++
575586 (case cpicEntry of
576587 [] -> []
@@ -725,19 +736,12 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
725736 unode "option" ! [("name","specified-fonts")] $ "true"
726737 let appleEntry = mkEntry "META-INF/com.apple.ibooks.display-options.xml" apple
727738
728− -- stylesheet
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
735−
736739 -- construct archive
737740 let archive = foldr addEntryToArchive emptyArchive
738− (mimetypeEntry : containerEntry : appleEntry : stylesheetEntry : tpEntry :
741+ (mimetypeEntry : containerEntry : appleEntry : tpEntry :
739742 contentsEntry : tocEntry : navEntry :
740− (picEntries ++ cpicEntry ++ cpgEntry ++ chapterEntries ++ fontEntries))
743+ (stylesheetEntries ++ picEntries ++ cpicEntry ++
744+ cpgEntry ++ chapterEntries ++ fontEntries))
741745 return $ fromArchive archive
742746
743747metadataElement :: EPUBVersion -> EPUBMetadata -> UTCTime -> Element