git.iko.soy/typeable/pandoc
on master help sign in
Revert "EPUB writer: stylesheet changes. Closes #2040."
7920a1aJohn MacFarlane
@@ -646,8 +646,6 @@ Options affecting specific writers
646 is specified, pandoc will look for a file `epub.css` in the
646 is specified, pandoc will look for a file `epub.css` in the
647 user data directory (see `--data-dir`). If it is not
647 user data directory (see `--data-dir`). If it is not
648 found there, sensible defaults will be used.
648 found there, sensible defaults will be used.
649− (*Deprecated:* use `--css` or the `stylesheet` metadata field
650− instead.)
651
649
652`--epub-cover-image=`*FILE*
650`--epub-cover-image=`*FILE*
653
651
pandoc.hs+2−4
@@ -689,10 +689,8 @@ options =
689 , Option "" ["epub-stylesheet"]
689 , Option "" ["epub-stylesheet"]
690 (ReqArg
690 (ReqArg
691 (\arg opt -> do
691 (\arg opt -> do
692− warn "--epub-stylesheet is deprecated. Use --css or stylesheet in metadata."
692+ text <- UTF8.readFile arg
693− let newvars = optVariables opt ++ [("css",arg)]
693+ return opt { optEpubStylesheet = Just text })
694− return opt { optVariables = newvars,
695− optStandalone = True })
696 "FILENAME")
694 "FILENAME")
697 "" -- "Path of epub.css"
695 "" -- "Path of epub.css"
698
696
src/Text/Pandoc/Writers/EPUB.hs+18−26
@@ -99,7 +99,7 @@ data EPUBMetadata = EPUBMetadata{
99 , epubPageDirection :: Maybe ProgressionDirection
99 , epubPageDirection :: Maybe ProgressionDirection
100 } deriving Show
100 } deriving Show
101
101
102−data Stylesheet = StylesheetPaths [FilePath]
102+data Stylesheet = StylesheetPath FilePath
103 | StylesheetContents String
103 | StylesheetContents String
104 deriving Show
104 deriving Show
105
105
@@ -323,14 +323,8 @@ metadataFromMeta opts meta = EPUBMetadata{
323 coverImage = lookup "epub-cover-image" (writerVariables opts) `mplus`
323 coverImage = lookup "epub-cover-image" (writerVariables opts) `mplus`
324 (metaValueToString <$> lookupMeta "cover-image" meta)
324 (metaValueToString <$> lookupMeta "cover-image" meta)
325 stylesheet = (StylesheetContents <$> writerEpubStylesheet opts) `mplus`
325 stylesheet = (StylesheetContents <$> writerEpubStylesheet opts) `mplus`
326+ ((StylesheetPath . metaValueToString) <$>
326− (case lookupMeta "stylesheet" meta of
327+ lookupMeta "stylesheet" meta)
327− Just (MetaBlocks [CodeBlock (_,["css"],_) code])
328− -> Just (StylesheetContents code)
329− Just x -> Just (StylesheetPaths [metaValueToString x])
330− Nothing -> Nothing) `mplus`
331− (case [x | ("css", x) <- writerVariables opts] of
332− [] -> Nothing
333− xs -> Just (StylesheetPaths xs))
334 pageDirection = case map toLower . metaValueToString <$>
328 pageDirection = case map toLower . metaValueToString <$>
335 lookupMeta "page-progression-direction" meta of
329 lookupMeta "page-progression-direction" meta of
336 Just "ltr" -> Just LTR
330 Just "ltr" -> Just LTR
@@ -346,21 +340,20 @@ writeEPUB opts doc@(Pandoc meta _) = do
346 let epub3 = version == EPUB3
340 let epub3 = version == EPUB3
347 epochtime <- floor `fmap` getPOSIXTime
341 epochtime <- floor `fmap` getPOSIXTime
348 let mkEntry path content = toEntry path epochtime content
342 let mkEntry path content = toEntry path epochtime content
349− let vars = ("epub3", if epub3 then "true" else "false") :
343+ let vars = ("epub3", if epub3 then "true" else "false")
344+ : ("css", "stylesheet.css")
350− writerVariables opts
345+ : writerVariables opts
351− let opts'' = opts{ writerEmailObfuscation = NoObfuscation
346+ let opts' = opts{ writerEmailObfuscation = NoObfuscation
352− , writerStandalone = True
347+ , writerStandalone = True
353− , writerSectionDivs = True
348+ , writerSectionDivs = True
354− , writerHtml5 = epub3
349+ , writerHtml5 = epub3
355− , writerVariables = vars
350+ , writerVariables = vars
356− , writerHTMLMathMethod =
351+ , writerHTMLMathMethod =
357− if epub3
352+ if epub3
358− then MathML Nothing
353+ then MathML Nothing
359− else writerHTMLMathMethod opts
354+ else writerHTMLMathMethod opts
360− , writerWrapText = True }
355+ , writerWrapText = True }
361− metadata <- getEPUBMetadata opts'' meta
356+ metadata <- getEPUBMetadata opts' meta
362− let opts' = opts''{ writerVariables = ("css", "stylesheet.css") :
363− filter (\(x,_) -> x /= "css") vars }
364
357
365 -- cover page
358 -- cover page
366 (cpgEntry, cpicEntry) <-
359 (cpgEntry, cpicEntry) <-
@@ -682,8 +675,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
682
675
683 -- stylesheet
676 -- stylesheet
684 stylesheet <- case epubStylesheet metadata of
677 stylesheet <- case epubStylesheet metadata of
685− Just (StylesheetPaths fp) -> concat <$>
686− mapM UTF8.readFile fp
678+ Just (StylesheetPath fp) -> UTF8.readFile fp
687 Just (StylesheetContents s) -> return s
679 Just (StylesheetContents s) -> return s
688 Nothing -> UTF8.toString `fmap`
680 Nothing -> UTF8.toString `fmap`
689 readDataFile (writerUserDataDir opts) "epub.css"
681 readDataFile (writerUserDataDir opts) "epub.css"