diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-05-08 23:46:02 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-05-08 23:47:50 -0700 |
commit | 1c2951dfd9ee72e5270cb974a06098adb9178f89 (patch) | |
tree | 8bd06bd47431b6de127d19f401986dea1882fd72 /src/Text | |
parent | 41a457a649cb981c703375181964314523546d72 (diff) | |
download | pandoc-1c2951dfd9ee72e5270cb974a06098adb9178f89.tar.gz |
EPUB writer: stylesheet changes. Closes #2040.
* Allow `--css` to be used to specify stylesheets.
* Deprecated `--epub-stylesheet` and made it a synoynym of
`--css`.
* If a code block with class "css" is given as contents of the
`stylesheet` metadata field, use its literal code as contents of
the epub stylesheet. Otherwise, treat it as a filename and
read the file.
* Note: `--css` and `stylesheet` in metadata are not compatible.
`stylesheet` takes precedence.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Writers/EPUB.hs | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index 37c285dc2..f35d2d245 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 = StylesheetPath FilePath +data Stylesheet = StylesheetPaths [FilePath] | StylesheetContents String deriving Show @@ -323,8 +323,14 @@ metadataFromMeta opts meta = EPUBMetadata{ coverImage = lookup "epub-cover-image" (writerVariables opts) `mplus` (metaValueToString <$> lookupMeta "cover-image" meta) stylesheet = (StylesheetContents <$> writerEpubStylesheet opts) `mplus` - ((StylesheetPath . metaValueToString) <$> - lookupMeta "stylesheet" meta) + (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)) pageDirection = case map toLower . metaValueToString <$> lookupMeta "page-progression-direction" meta of Just "ltr" -> Just LTR @@ -340,20 +346,21 @@ 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") - : ("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 + 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 } -- cover page (cpgEntry, cpicEntry) <- @@ -675,7 +682,8 @@ writeEPUB opts doc@(Pandoc meta _) = do -- stylesheet stylesheet <- case epubStylesheet metadata of - Just (StylesheetPath fp) -> UTF8.readFile fp + Just (StylesheetPaths fp) -> concat <$> + mapM UTF8.readFile fp Just (StylesheetContents s) -> return s Nothing -> UTF8.toString `fmap` readDataFile (writerUserDataDir opts) "epub.css" |