summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-05-09 00:07:27 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-05-09 00:07:27 -0700
commit7920a1a46987c8d57e12ffc134a9da9a9a4e9ecb (patch)
tree27e01aa9e25840227e961519a2763e5b2cd5699c
parent1c2951dfd9ee72e5270cb974a06098adb9178f89 (diff)
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`.
-rw-r--r--README2
-rw-r--r--pandoc.hs6
-rw-r--r--src/Text/Pandoc/Writers/EPUB.hs44
3 files changed, 20 insertions, 32 deletions
diff --git a/README b/README
index 10097f4b7..fa93bf8e5 100644
--- a/README
+++ b/README
@@ -646,8 +646,6 @@ Options affecting specific writers
is specified, pandoc will look for a file `epub.css` in the
user data directory (see `--data-dir`). If it is not
found there, sensible defaults will be used.
- (*Deprecated:* use `--css` or the `stylesheet` metadata field
- instead.)
`--epub-cover-image=`*FILE*
diff --git a/pandoc.hs b/pandoc.hs
index 45e5de5f2..9023b2625 100644
--- a/pandoc.hs
+++ b/pandoc.hs
@@ -689,10 +689,8 @@ options =
, Option "" ["epub-stylesheet"]
(ReqArg
(\arg opt -> do
- warn "--epub-stylesheet is deprecated. Use --css or stylesheet in metadata."
- let newvars = optVariables opt ++ [("css",arg)]
- return opt { optVariables = newvars,
- optStandalone = True })
+ text <- UTF8.readFile arg
+ return opt { optEpubStylesheet = Just text })
"FILENAME")
"" -- "Path of epub.css"
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs
index f35d2d245..37c285dc2 100644
--- a/src/Text/Pandoc/Writers/EPUB.hs
+++ b/src/Text/Pandoc/Writers/EPUB.hs
@@ -99,7 +99,7 @@ data EPUBMetadata = EPUBMetadata{
, epubPageDirection :: Maybe ProgressionDirection
} deriving Show
-data Stylesheet = StylesheetPaths [FilePath]
+data Stylesheet = StylesheetPath FilePath
| StylesheetContents String
deriving Show
@@ -323,14 +323,8 @@ metadataFromMeta opts meta = EPUBMetadata{
coverImage = lookup "epub-cover-image" (writerVariables opts) `mplus`
(metaValueToString <$> lookupMeta "cover-image" meta)
stylesheet = (StylesheetContents <$> writerEpubStylesheet opts) `mplus`
- (case lookupMeta "stylesheet" meta of
- Just (MetaBlocks [CodeBlock (_,["css"],_) code])
- -> Just (StylesheetContents code)
- Just x -> Just (StylesheetPaths [metaValueToString x])
- Nothing -> Nothing) `mplus`
- (case [x | ("css", x) <- writerVariables opts] of
- [] -> Nothing
- xs -> Just (StylesheetPaths xs))
+ ((StylesheetPath . metaValueToString) <$>
+ lookupMeta "stylesheet" meta)
pageDirection = case map toLower . metaValueToString <$>
lookupMeta "page-progression-direction" meta of
Just "ltr" -> Just LTR
@@ -346,21 +340,20 @@ writeEPUB opts doc@(Pandoc meta _) = do
let epub3 = version == EPUB3
epochtime <- floor `fmap` getPOSIXTime
let mkEntry path content = toEntry path epochtime content
- let vars = ("epub3", if epub3 then "true" else "false") :
- writerVariables opts
- let opts'' = opts{ writerEmailObfuscation = NoObfuscation
- , writerStandalone = True
- , writerSectionDivs = True
- , writerHtml5 = epub3
- , writerVariables = vars
- , writerHTMLMathMethod =
- if epub3
- then MathML Nothing
- else writerHTMLMathMethod opts
- , writerWrapText = True }
- metadata <- getEPUBMetadata opts'' meta
- let opts' = opts''{ writerVariables = ("css", "stylesheet.css") :
- filter (\(x,_) -> x /= "css") vars }
+ let vars = ("epub3", if epub3 then "true" else "false")
+ : ("css", "stylesheet.css")
+ : writerVariables opts
+ let opts' = opts{ writerEmailObfuscation = NoObfuscation
+ , writerStandalone = True
+ , writerSectionDivs = True
+ , writerHtml5 = epub3
+ , writerVariables = vars
+ , writerHTMLMathMethod =
+ if epub3
+ then MathML Nothing
+ else writerHTMLMathMethod opts
+ , writerWrapText = True }
+ metadata <- getEPUBMetadata opts' meta
-- cover page
(cpgEntry, cpicEntry) <-
@@ -682,8 +675,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
-- stylesheet
stylesheet <- case epubStylesheet metadata of
- Just (StylesheetPaths fp) -> concat <$>
- mapM UTF8.readFile fp
+ Just (StylesheetPath fp) -> UTF8.readFile fp
Just (StylesheetContents s) -> return s
Nothing -> UTF8.toString `fmap`
readDataFile (writerUserDataDir opts) "epub.css"