@@ -43,7 +43,7 @@ import qualified Data.ByteString.Lazy.Char8 as B8
4343import Data.Char (isAlphaNum, isAscii, isDigit, toLower)
4444import Data.List (intercalate, isInfixOf, isPrefixOf)
4545import qualified Data.Map as M
46−import Data.Maybe (fromMaybe, isNothing, mapMaybe)
46+import Data.Maybe (fromMaybe, isNothing, mapMaybe, isJust)
4747import qualified Data.Set as Set
4848import qualified Data.Text as TS
4949import qualified Data.Text.Lazy as TL
@@ -399,8 +399,11 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
399399 stylesheets [(1 :: Int)..]
400400
401401 let vars = ("epub3", if epub3 then "true" else "false")
402− : map (\e -> ("css", "../" ++ eRelativePath e)) stylesheetEntries
403− ++ [(x,y) | (x,y) <- writerVariables opts, x /= "css"]
402+ : [(x,y) | (x,y) <- writerVariables opts, x /= "css"]
403+
404+ let cssvars pref = map (\e -> ("css", pref ++ eRelativePath e))
405+ stylesheetEntries
406+
404407 let opts' = opts{ writerEmailObfuscation = NoObfuscation
405408 , writerSectionDivs = True
406409 , writerVariables = vars
@@ -417,7 +420,9 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
417420 Just img -> do
418421 let coverImage = "media/" ++ takeFileName img
419422 cpContent <- lift $ writeHtml
420− opts'{ writerVariables = ("coverpage","true"):vars }
423+ opts'{ writerVariables =
424+ ("coverpage","true"):
425+ cssvars "" ++ vars }
421426 (Pandoc meta [RawBlock (Format "html") $ "<div id=\"cover-image\">\n<img src=\"" ++ coverImage ++ "\" alt=\"cover image\" />\n</div>"])
422427 imgContent <- lift $ P.readFileLazy img
423428 return ( [mkEntry "cover.xhtml" cpContent]
@@ -425,7 +430,8 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
425430
426431 -- title page
427432 tpContent <- lift $ writeHtml opts'{
428− writerVariables = ("titlepage","true"):vars }
433+ writerVariables = ("titlepage","true"):
434+ cssvars "../" ++ vars }
429435 (Pandoc meta [])
430436 let tpEntry = mkEntry "text/title_page.xhtml" tpContent
431437
@@ -527,13 +533,14 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
527533
528534 let chapToEntry num (Chapter mbnum bs) =
529535 mkEntry ("text/" ++ showChapter num) <$>
530− writeHtml opts'{ writerNumberOffset = fromMaybe [] mbnum } (case bs of
531− (Header _ _ xs : _) ->
532− -- remove notes or we get doubled footnotes
533− Pandoc (setMeta "title" (walk removeNote $ fromList xs)
534− nullMeta) bs
535− _ ->
536− Pandoc nullMeta bs)
536+ writeHtml opts'{ writerNumberOffset = fromMaybe [] mbnum
537+ , writerVariables = cssvars "../" ++ vars }
538+ (case bs of
539+ (Header _ _ xs : _) ->
540+ -- remove notes or we get doubled footnotes
541+ Pandoc (setMeta "title" (walk removeNote $ fromList xs)
542+ nullMeta) bs
543+ _ -> Pandoc nullMeta bs)
537544
538545 chapterEntries <- lift $ zipWithM chapToEntry [1..] chapters
539546
@@ -579,12 +586,14 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
579586 [] -> throwError $ PandocShouldNeverHappenError "epubIdentifier is null" -- shouldn't happen
580587 currentTime <- lift P.getCurrentTime
581588 let contentsData = UTF8.fromStringLazy $ ppTopElement $
582− unode "package" ! [("version", case version of
583− EPUB2 -> "2.0"
584− EPUB3 -> "3.0")
585− ,("xmlns","http://www.idpf.org/2007/opf")
586− ,("unique-identifier","epub-id-1")
587− ,("prefix","ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/")] $
589+ unode "package" !
590+ ([("version", case version of
591+ EPUB2 -> "2.0"
592+ EPUB3 -> "3.0")
593+ ,("xmlns","http://www.idpf.org/2007/opf")
594+ ,("unique-identifier","epub-id-1")
595+ ] ++
596+ [("prefix","ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/") | version == EPUB3]) $
588597 [ metadataElement version metadata currentTime
589598 , unode "manifest" $
590599 [ unode "item" ! [("id","ncx"), ("href","toc.ncx")
@@ -625,7 +634,10 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
625634 ("href","nav.xhtml")] $ ()
626635 ] ++
627636 [ unode "reference" !
628− [("type","cover"),("title","Cover"),("href","cover.xhtml")] $ () | epubCoverImage metadata /= Nothing
637+ [("type","cover")
638+ ,("title","Cover")
639+ ,("href","cover.xhtml")] $ ()
640+ | isJust (epubCoverImage metadata)
629641 ]
630642 ]
631643 let contentsEntry = mkEntry "content.opf" contentsData
@@ -741,10 +753,7 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
741753 ]
742754 else []
743755 navData <- lift $ writeHtml opts'{ writerVariables = ("navpage","true"):
744− -- remove the leading ../ from stylesheet paths:
745− map (\(k,v) -> if k == "css"
746− then (k, drop 3 v)
747− else (k, v)) vars }
756+ cssvars "" ++ vars }
748757 (Pandoc (setMeta "title"
749758 (walk removeNote $ fromList $ docTitle' meta) nullMeta)
750759 (navBlocks ++ landmarks))