git.iko.soy/typeable/pandoc
on master help sign in
Removed `--epub-stylesheet`; use `--css` instead.
c7e2c71John MacFarlane
MANUAL.txt+7−8
@@ -758,6 +758,12 @@ Options affecting specific writers
758: Link to a CSS style sheet. This option can be used repeatedly to
758: Link to a CSS style sheet. This option can be used repeatedly to
759 include multiple files. They will be included in the order specified.
759 include multiple files. They will be included in the order specified.
760
760
761+ A stylesheet is required for generating EPUB. If none is
762+ provided using this option (or the `stylesheet` metadata
763+ field), pandoc will look for a file `epub.css` in the
764+ user data directory (see `--data-dir`). If it is not
765+ found there, sensible defaults will be used.
766+
761`--reference-doc=`*FILE*
767`--reference-doc=`*FILE*
762
768
763: Use the specified file as a style reference in producing a
769: Use the specified file as a style reference in producing a
@@ -804,13 +810,6 @@ Options affecting specific writers
804 LibreOffice, modify the styles as you wish, and save the
810 LibreOffice, modify the styles as you wish, and save the
805 file.
811 file.
806
812
807−`--epub-stylesheet=`*FILE*
808−
809−: Use the specified CSS file to style the EPUB. If no stylesheet
810− is specified, pandoc will look for a file `epub.css` in the
811− user data directory (see `--data-dir`). If it is not
812− found there, sensible defaults will be used.
813−
814`--epub-cover-image=`*FILE*
813`--epub-cover-image=`*FILE*
815
814
816: Use the specified image as the EPUB cover. It is recommended
815: Use the specified image as the EPUB cover. It is recommended
@@ -847,7 +846,7 @@ Options affecting specific writers
847 line, be sure to escape them or put the whole filename in single quotes,
846 line, be sure to escape them or put the whole filename in single quotes,
848 to prevent them from being interpreted by the shell. To use the
847 to prevent them from being interpreted by the shell. To use the
849 embedded fonts, you will need to add declarations like the following
848 embedded fonts, you will need to add declarations like the following
850− to your CSS (see `--epub-stylesheet`):
849+ to your CSS (see `--css`):
851
850
852 @font-face {
851 @font-face {
853 font-family: DejaVuSans;
852 font-family: DejaVuSans;
src/Text/Pandoc/App.hs+2−13
@@ -112,10 +112,6 @@ convertWithOpts opts = do
112 mapM_ (UTF8.hPutStrLn stdout) args
112 mapM_ (UTF8.hPutStrLn stdout) args
113 exitSuccess
113 exitSuccess
114
114
115− epubStylesheet <- case optEpubStylesheet opts of
116− Nothing -> return Nothing
117− Just fp -> Just <$> UTF8.readFile fp
118−
119 epubMetadata <- case optEpubMetadata opts of
115 epubMetadata <- case optEpubMetadata opts of
120 Nothing -> return Nothing
116 Nothing -> return Nothing
121 Just fp -> Just <$> UTF8.readFile fp
117 Just fp -> Just <$> UTF8.readFile fp
@@ -319,7 +315,6 @@ convertWithOpts opts = do
319 writerHighlightStyle = highlightStyle,
315 writerHighlightStyle = highlightStyle,
320 writerSetextHeaders = optSetextHeaders opts,
316 writerSetextHeaders = optSetextHeaders opts,
321 writerEpubMetadata = epubMetadata,
317 writerEpubMetadata = epubMetadata,
322− writerEpubStylesheet = epubStylesheet,
323 writerEpubFonts = optEpubFonts opts,
318 writerEpubFonts = optEpubFonts opts,
324 writerEpubChapterLevel = optEpubChapterLevel opts,
319 writerEpubChapterLevel = optEpubChapterLevel opts,
325 writerTOCDepth = optTOCDepth opts,
320 writerTOCDepth = optTOCDepth opts,
@@ -493,7 +488,6 @@ data Opt = Opt
493 , optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
488 , optTopLevelDivision :: TopLevelDivision -- ^ Type of the top-level divisions
494 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
489 , optHTMLMathMethod :: HTMLMathMethod -- ^ Method to print HTML math
495 , optReferenceDoc :: Maybe FilePath -- ^ Path of reference doc
490 , optReferenceDoc :: Maybe FilePath -- ^ Path of reference doc
496− , optEpubStylesheet :: Maybe FilePath -- ^ EPUB stylesheet
497 , optEpubMetadata :: Maybe FilePath -- ^ EPUB metadata
491 , optEpubMetadata :: Maybe FilePath -- ^ EPUB metadata
498 , optEpubFonts :: [FilePath] -- ^ EPUB fonts to embed
492 , optEpubFonts :: [FilePath] -- ^ EPUB fonts to embed
499 , optEpubChapterLevel :: Int -- ^ Header level at which to split chapters
493 , optEpubChapterLevel :: Int -- ^ Header level at which to split chapters
@@ -559,7 +553,6 @@ defaultOpts = Opt
559 , optTopLevelDivision = TopLevelDefault
553 , optTopLevelDivision = TopLevelDefault
560 , optHTMLMathMethod = PlainMath
554 , optHTMLMathMethod = PlainMath
561 , optReferenceDoc = Nothing
555 , optReferenceDoc = Nothing
562− , optEpubStylesheet = Nothing
563 , optEpubMetadata = Nothing
556 , optEpubMetadata = Nothing
564 , optEpubFonts = []
557 , optEpubFonts = []
565 , optEpubChapterLevel = 1
558 , optEpubChapterLevel = 1
@@ -1118,12 +1111,6 @@ options =
1118 "FILENAME")
1111 "FILENAME")
1119 "" -- "Path of custom reference doc"
1112 "" -- "Path of custom reference doc"
1120
1113
1121− , Option "" ["epub-stylesheet"]
1122− (ReqArg
1123− (\arg opt -> return opt { optEpubStylesheet = Just arg })
1124− "FILENAME")
1125− "" -- "Path of epub.css"
1126−
1127 , Option "" ["epub-cover-image"]
1114 , Option "" ["epub-cover-image"]
1128 (ReqArg
1115 (ReqArg
1129 (\arg opt ->
1116 (\arg opt ->
@@ -1430,6 +1417,8 @@ handleUnrecognizedOption "--reference-odt" =
1430 ("--reference-odt has been removed. Use --reference-doc instead." :)
1417 ("--reference-odt has been removed. Use --reference-doc instead." :)
1431handleUnrecognizedOption "--parse-raw" =
1418handleUnrecognizedOption "--parse-raw" =
1432 (("--parse-raw/-R has been removed. Use +raw_html or +raw_tex extension.\n") :)
1419 (("--parse-raw/-R has been removed. Use +raw_html or +raw_tex extension.\n") :)
1420+handleUnrecognizedOption "--epub-stylesheet" =
1421+ (("--epub-stylesheet has been removed. Use --css instead.\n") :)
1433handleUnrecognizedOption "-R" = handleUnrecognizedOption "--parse-raw"
1422handleUnrecognizedOption "-R" = handleUnrecognizedOption "--parse-raw"
1434handleUnrecognizedOption x =
1423handleUnrecognizedOption x =
1435 (("Unknown option " ++ x ++ ".") :)
1424 (("Unknown option " ++ x ++ ".") :)
src/Text/Pandoc/Options.hs−2
@@ -167,7 +167,6 @@ data WriterOptions = WriterOptions
167 -- (Nothing = no highlighting)
167 -- (Nothing = no highlighting)
168 , writerSetextHeaders :: Bool -- ^ Use setext headers for levels 1-2 in markdown
168 , writerSetextHeaders :: Bool -- ^ Use setext headers for levels 1-2 in markdown
169 , writerEpubMetadata :: Maybe String -- ^ Metadata to include in EPUB
169 , writerEpubMetadata :: Maybe String -- ^ Metadata to include in EPUB
170− , writerEpubStylesheet :: Maybe String -- ^ EPUB stylesheet specified at command line
171 , writerEpubFonts :: [FilePath] -- ^ Paths to fonts to embed
170 , writerEpubFonts :: [FilePath] -- ^ Paths to fonts to embed
172 , writerEpubChapterLevel :: Int -- ^ Header level for chapters (separate files)
171 , writerEpubChapterLevel :: Int -- ^ Header level for chapters (separate files)
173 , writerTOCDepth :: Int -- ^ Number of levels to include in TOC
172 , writerTOCDepth :: Int -- ^ Number of levels to include in TOC
@@ -203,7 +202,6 @@ instance Default WriterOptions where
203 , writerHighlightStyle = Just pygments
202 , writerHighlightStyle = Just pygments
204 , writerSetextHeaders = True
203 , writerSetextHeaders = True
205 , writerEpubMetadata = Nothing
204 , writerEpubMetadata = Nothing
206− , writerEpubStylesheet = Nothing
207 , writerEpubFonts = []
205 , writerEpubFonts = []
208 , writerEpubChapterLevel = 1
206 , writerEpubChapterLevel = 1
209 , writerTOCDepth = 3
207 , writerTOCDepth = 3
src/Text/Pandoc/Writers/EPUB.hs+28−24
@@ -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
104
104
105−data Stylesheet = StylesheetPath FilePath
106− | StylesheetContents String
107− deriving Show
108−
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 _ = ""
242
238
239+metaValueToPaths:: MetaValue -> [FilePath]
240+metaValueToPaths (MetaList xs) = map metaValueToString xs
241+metaValueToPaths x = [metaValueToString x]
242+
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
312 }
312 }
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
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+
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
390
400
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 ]) $ ()
573 ] ++
581 ] ++
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
576 [] -> []
587 [] -> []
@@ -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
727
738
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−
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
742
746
743metadataElement :: EPUBVersion -> EPUBMetadata -> UTCTime -> Element
747metadataElement :: EPUBVersion -> EPUBMetadata -> UTCTime -> Element