git.iko.soy/typeable/pandoc
on master help sign in
Revert "EPUB writer: stylesheet changes. Closes #2040."

This reverts commit 1c2951dfd9ee72e5270cb974a06098adb9178f89. See #2040. The semantics was too squishy. `--css` takes a URL, but for EPUB we need files that we can read. I prefer keeping the old system for now, with `--epub-stylesheet`.

commit7920a1a46987c8d57e12ffc134a9da9a9a4e9ecb authorJohn MacFarlane <jgm@berkeley.edu> dateSat 9 May 2015, 00:07 (11 years ago) parent1c2951d
3 files changed+20−32
README−2 pandoc.hs+2−4 src/Text/Pandoc/Writers/EPUB.hs+18−26
README−2
@@ -646,8 +646,6 @@ Options affecting specific writers
646646 is specified, pandoc will look for a file `epub.css` in the
647647 user data directory (see `--data-dir`). If it is not
648648 found there, sensible defaults will be used.
649− (*Deprecated:* use `--css` or the `stylesheet` metadata field
650− instead.)
651649
652650`--epub-cover-image=`*FILE*
653651
pandoc.hs+2−4
@@ -689,10 +689,8 @@ options =
689689 , Option "" ["epub-stylesheet"]
690690 (ReqArg
691691 (\arg opt -> do
692− warn "--epub-stylesheet is deprecated. Use --css or stylesheet in metadata."
693− let newvars = optVariables opt ++ [("css",arg)]
694− return opt { optVariables = newvars,
695− optStandalone = True })
692+ text <- UTF8.readFile arg
693+ return opt { optEpubStylesheet = Just text })
696694 "FILENAME")
697695 "" -- "Path of epub.css"
698696
src/Text/Pandoc/Writers/EPUB.hs+18−26
@@ -99,7 +99,7 @@ data EPUBMetadata = EPUBMetadata{
9999 , epubPageDirection :: Maybe ProgressionDirection
100100 } deriving Show
101101
102−data Stylesheet = StylesheetPaths [FilePath]
102+data Stylesheet = StylesheetPath FilePath
103103 | StylesheetContents String
104104 deriving Show
105105
@@ -323,14 +323,8 @@ metadataFromMeta opts meta = EPUBMetadata{
323323 coverImage = lookup "epub-cover-image" (writerVariables opts) `mplus`
324324 (metaValueToString <$> lookupMeta "cover-image" meta)
325325 stylesheet = (StylesheetContents <$> writerEpubStylesheet opts) `mplus`
326− (case lookupMeta "stylesheet" meta of
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))
326+ ((StylesheetPath . metaValueToString) <$>
327+ lookupMeta "stylesheet" meta)
334328 pageDirection = case map toLower . metaValueToString <$>
335329 lookupMeta "page-progression-direction" meta of
336330 Just "ltr" -> Just LTR
@@ -346,21 +340,20 @@ writeEPUB opts doc@(Pandoc meta _) = do
346340 let epub3 = version == EPUB3
347341 epochtime <- floor `fmap` getPOSIXTime
348342 let mkEntry path content = toEntry path epochtime content
349− let vars = ("epub3", if epub3 then "true" else "false") :
350− writerVariables opts
351− let opts'' = opts{ writerEmailObfuscation = NoObfuscation
352− , writerStandalone = True
353− , writerSectionDivs = True
354− , writerHtml5 = epub3
355− , writerVariables = vars
356− , writerHTMLMathMethod =
357− if epub3
358− then MathML Nothing
359− else writerHTMLMathMethod opts
360− , writerWrapText = True }
361− metadata <- getEPUBMetadata opts'' meta
362− let opts' = opts''{ writerVariables = ("css", "stylesheet.css") :
363− filter (\(x,_) -> x /= "css") vars }
343+ let vars = ("epub3", if epub3 then "true" else "false")
344+ : ("css", "stylesheet.css")
345+ : writerVariables opts
346+ let opts' = opts{ writerEmailObfuscation = NoObfuscation
347+ , writerStandalone = True
348+ , writerSectionDivs = True
349+ , writerHtml5 = epub3
350+ , writerVariables = vars
351+ , writerHTMLMathMethod =
352+ if epub3
353+ then MathML Nothing
354+ else writerHTMLMathMethod opts
355+ , writerWrapText = True }
356+ metadata <- getEPUBMetadata opts' meta
364357
365358 -- cover page
366359 (cpgEntry, cpicEntry) <-
@@ -682,8 +675,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
682675
683676 -- stylesheet
684677 stylesheet <- case epubStylesheet metadata of
685− Just (StylesheetPaths fp) -> concat <$>
686− mapM UTF8.readFile fp
678+ Just (StylesheetPath fp) -> UTF8.readFile fp
687679 Just (StylesheetContents s) -> return s
688680 Nothing -> UTF8.toString `fmap`
689681 readDataFile (writerUserDataDir opts) "epub.css"