aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers/EPUB.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/Writers/EPUB.hs')
-rw-r--r--src/Text/Pandoc/Writers/EPUB.hs35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs
index 7b4853a24..f1ff8b482 100644
--- a/src/Text/Pandoc/Writers/EPUB.hs
+++ b/src/Text/Pandoc/Writers/EPUB.hs
@@ -1,3 +1,4 @@
+{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE PatternGuards #-}
@@ -32,6 +33,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Conversion of 'Pandoc' documents to EPUB.
-}
module Text.Pandoc.Writers.EPUB ( writeEPUB2, writeEPUB3 ) where
+import Prelude
import Codec.Archive.Zip (Entry, addEntryToArchive, eRelativePath, emptyArchive,
fromArchive, fromEntry, toEntry)
import Control.Monad (mplus, unless, when, zipWithM)
@@ -53,7 +55,7 @@ import Text.HTML.TagSoup (Tag (TagOpen), fromAttrib, parseTags)
import Text.Pandoc.Builder (fromList, setMeta)
import Text.Pandoc.Class (PandocMonad, report)
import qualified Text.Pandoc.Class as P
-import Text.Pandoc.Compat.Time
+import Data.Time
import Text.Pandoc.Definition
import Text.Pandoc.Error
import Text.Pandoc.Logging
@@ -401,6 +403,12 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
writeHtmlStringForEPUB version o
metadata <- getEPUBMetadata opts meta
+ let plainTitle = case docTitle' meta of
+ [] -> case epubTitle metadata of
+ [] -> "UNTITLED"
+ (x:_) -> titleText x
+ x -> stringify x
+
-- stylesheet
stylesheets <- case epubStylesheets metadata of
[] -> (\x -> [B.fromChunks [x]]) <$>
@@ -438,6 +446,7 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
cpContent <- lift $ writeHtml
opts'{ writerVariables =
("coverpage","true"):
+ ("pagetitle",plainTitle):
cssvars True ++ vars }
(Pandoc meta [RawBlock (Format "html") $ "<div id=\"cover-image\">\n<img src=\"../media/" ++ coverImage ++ "\" alt=\"cover image\" />\n</div>"])
imgContent <- lift $ P.readFileLazy img
@@ -450,6 +459,7 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
-- title page
tpContent <- lift $ writeHtml opts'{
writerVariables = ("titlepage","true"):
+ ("pagetitle",plainTitle):
cssvars True ++ vars }
(Pandoc meta [])
tpEntry <- mkEntry "text/title_page.xhtml" tpContent
@@ -458,7 +468,7 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
-- mediaRef <- P.newIORef []
Pandoc _ blocks <- walkM (transformInline opts') doc >>=
walkM transformBlock
- picEntries <- (mapMaybe (snd . snd)) <$> gets stMediaPaths
+ picEntries <- mapMaybe (snd . snd) <$> gets stMediaPaths
-- handle fonts
let matchingGlob f = do
xs <- lift $ P.glob f
@@ -602,11 +612,6 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
$ eRelativePath ent),
("media-type", fromMaybe "" $
getMimeType $ eRelativePath ent)] $ ()
- let plainTitle = case docTitle' meta of
- [] -> case epubTitle metadata of
- [] -> "UNTITLED"
- (x:_) -> titleText x
- x -> stringify x
let tocTitle = fromMaybe plainTitle $
metaValueToString <$> lookupMeta "toc-title" meta
@@ -747,14 +752,18 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
where titElements = parseXML titRendered
titRendered = case P.runPure
(writeHtmlStringForEPUB version
- opts{ writerTemplate = Nothing }
+ opts{ writerTemplate = Nothing
+ , writerVariables =
+ ("pagetitle",plainTitle):
+ writerVariables opts}
(Pandoc nullMeta
- [Plain $ walk delink tit])) of
+ [Plain $ walk clean tit])) of
Left _ -> TS.pack $ stringify tit
Right x -> x
- -- can't have a element inside a...
- delink (Link _ ils _) = Span ("", [], []) ils
- delink x = x
+ -- can't have <a> elements inside generated links...
+ clean (Link _ ils _) = Span ("", [], []) ils
+ clean (Note _) = Str ""
+ clean x = x
let navtag = if epub3 then "nav" else "div"
tocBlocks <- lift $ evalStateT (mapM (navPointNode navXhtmlFormatter) secs) 1
@@ -872,7 +881,7 @@ metadataElement version md currentTime =
dcTag' n s = [dcTag n s]
toIdentifierNode id' (Identifier txt scheme)
| version == EPUB2 = [dcNode "identifier" !
- ([("id",id')] ++ maybe [] (\x -> [("opf:scheme", x)]) scheme) $
+ (("id",id') : maybe [] (\x -> [("opf:scheme", x)]) scheme) $
txt]
| otherwise = [dcNode "identifier" ! [("id",id')] $ txt] ++
maybe [] (\x -> [unode "meta" !