aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-09-30 17:19:07 -0500
committerJohn MacFarlane <jgm@berkeley.edu>2017-09-30 17:19:07 -0500
commit99aba1e7886d27ede519dede87652e0bda9a1d08 (patch)
tree160fed83536e913d9ea2ac11d68304e45f78fa87 /src
parent9004da4587b41b0f24a1a646a03fa9a092e50864 (diff)
downloadpandoc-99aba1e7886d27ede519dede87652e0bda9a1d08.tar.gz
EPUB writer: simplified some functions.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/EPUB.hs42
1 files changed, 18 insertions, 24 deletions
diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs
index 6bae65b6b..c75845fa9 100644
--- a/src/Text/Pandoc/Writers/EPUB.hs
+++ b/src/Text/Pandoc/Writers/EPUB.hs
@@ -433,7 +433,7 @@ pandocToEPUB version opts doc@(Pandoc meta _) = do
-- handle pictures
-- mediaRef <- P.newIORef []
Pandoc _ blocks <- walkM (transformInline opts') doc >>=
- walkM (transformBlock opts')
+ walkM transformBlock
picEntries <- (catMaybes . map (snd . snd)) <$> (gets stMediaPaths)
-- handle fonts
let matchingGlob f = do
@@ -891,29 +891,26 @@ showDateTimeISO8601 :: UTCTime -> String
showDateTimeISO8601 = formatTime defaultTimeLocale "%FT%TZ"
transformTag :: PandocMonad m
- => WriterOptions
- -- -> IORef [(FilePath, (FilePath, Maybe Entry))] -- ^ (oldpath, newpath, entry) media
- -> Tag String
+ => Tag String
-> E m (Tag String)
-transformTag opts tag@(TagOpen name attr)
+transformTag tag@(TagOpen name attr)
| name `elem` ["video", "source", "img", "audio"] &&
lookup "data-external" attr == Nothing = do
let src = fromAttrib "src" tag
let poster = fromAttrib "poster" tag
- newsrc <- modifyMediaRef opts src
- newposter <- modifyMediaRef opts poster
+ newsrc <- modifyMediaRef src
+ newposter <- modifyMediaRef poster
let attr' = filter (\(x,_) -> x /= "src" && x /= "poster") attr ++
[("src", newsrc) | not (null newsrc)] ++
[("poster", newposter) | not (null newposter)]
return $ TagOpen name attr'
-transformTag _ tag = return tag
+transformTag tag = return tag
modifyMediaRef :: PandocMonad m
- => WriterOptions
- -> FilePath
+ => FilePath
-> E m FilePath
-modifyMediaRef _ "" = return ""
-modifyMediaRef opts oldsrc = do
+modifyMediaRef "" = return ""
+modifyMediaRef oldsrc = do
media <- gets stMediaPaths
case lookup oldsrc media of
Just (n,_) -> return n
@@ -932,35 +929,32 @@ modifyMediaRef opts oldsrc = do
return oldsrc)
transformBlock :: PandocMonad m
- => WriterOptions
- -- -> IORef [(FilePath, (FilePath, Maybe Entry))] -- ^ (oldpath, newpath, entry) media
- -> Block
+ => Block
-> E m Block
-transformBlock opts (RawBlock fmt raw)
+transformBlock (RawBlock fmt raw)
| fmt == Format "html" = do
let tags = parseTags raw
- tags' <- mapM (transformTag opts) tags
+ tags' <- mapM transformTag tags
return $ RawBlock fmt (renderTags' tags')
-transformBlock _ b = return b
+transformBlock b = return b
transformInline :: PandocMonad m
=> WriterOptions
- -- -> IORef [(FilePath, (FilePath, Maybe Entry))] -- ^ (oldpath, newpath) media
-> Inline
-> E m Inline
-transformInline opts (Image attr lab (src,tit)) = do
- newsrc <- modifyMediaRef opts src
+transformInline _opts (Image attr lab (src,tit)) = do
+ newsrc <- modifyMediaRef src
return $ Image attr lab ("../" ++ newsrc, tit)
transformInline opts (x@(Math t m))
| WebTeX url <- writerHTMLMathMethod opts = do
- newsrc <- modifyMediaRef opts (url ++ urlEncode m)
+ newsrc <- modifyMediaRef (url ++ urlEncode m)
let mathclass = if t == DisplayMath then "display" else "inline"
return $ Span ("",["math",mathclass],[])
[Image nullAttr [x] ("../" ++ newsrc, "")]
-transformInline opts (RawInline fmt raw)
+transformInline _opts (RawInline fmt raw)
| fmt == Format "html" = do
let tags = parseTags raw
- tags' <- mapM (transformTag opts) tags
+ tags' <- mapM transformTag tags
return $ RawInline fmt (renderTags' tags')
transformInline _ x = return x