@@ -1,3 +1,4 @@
1+{-# LANGUAGE PatternGuards #-}
12{-
23Copyright (C) 2010 John MacFarlane <jgm@berkeley.edu>
34
@@ -30,7 +31,7 @@ Conversion of 'Pandoc' documents to EPUB.
3031module Text.Pandoc.Writers.EPUB ( writeEPUB ) where
3132import Data.IORef
3233import Data.Maybe ( fromMaybe, isNothing )
33−import Data.List ( isInfixOf, intercalate, isPrefixOf )
34+import Data.List ( isInfixOf, intercalate )
3435import System.Environment ( getEnv )
3536import Text.Printf (printf)
3637import System.FilePath ( (</>), takeBaseName, takeExtension, takeFileName )
@@ -53,7 +54,7 @@ import Text.Pandoc.UUID
5354import Text.Pandoc.Writers.HTML
5455import Text.Pandoc.Writers.Markdown ( writePlain )
5556import Data.Char ( toLower )
56−import Network.URI ( unEscapeString )
57+import Network.URI ( isAbsoluteURI, unEscapeString )
5758import Text.Pandoc.MIME (getMimeType)
5859import Prelude hiding (catch)
5960import Control.Exception (catch, SomeException)
@@ -116,7 +117,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
116117 -- handle pictures
117118 picsRef <- newIORef []
118119 Pandoc _ blocks <- bottomUpM
119− (transformInline (writerHTMLMathMethod opts') sourceDir picsRef) doc
120+ (transformInline opts' sourceDir picsRef) doc
120121 pics <- readIORef picsRef
121122 let readPicEntry (oldsrc, newsrc) = do
122123 (img,_) <- fetchItem sourceDir oldsrc
@@ -405,17 +406,16 @@ metadataElement version metadataXML uuid lang title authors date currentTime mbC
405406showDateTimeISO8601 :: UTCTime -> String
406407showDateTimeISO8601 = formatTime defaultTimeLocale "%FT%TZ"
407408
408−transformInline :: HTMLMathMethod
409+transformInline :: WriterOptions
409410 -> FilePath
410411 -> IORef [(FilePath, FilePath)] -- ^ (oldpath, newpath) images
411412 -> Inline
412413 -> IO Inline
413−transformInline _ sourceDir picsRef (Image lab (src,tit))
414− | "http://chart.apis.google.com" `isPrefixOf` src = do
415− raw <- makeSelfContained Nothing $
416− writeHtmlInline def (Image lab (src,tit))
417− return (RawInline "html" raw)
418− | isNothing (imageTypeOf src) = return $ Emph lab
414+transformInline opts sourceDir picsRef (Image lab (src,tit))
415+ | isAbsoluteURI src = do
416+ raw <- makeSelfContained Nothing
417+ $ writeHtmlInline opts (Image lab (src,tit))
418+ return $ RawInline "html" raw
419419 | otherwise = do
420420 let src' = unEscapeString src
421421 pics <- readIORef picsRef
@@ -428,17 +428,16 @@ transformInline _ sourceDir picsRef (Image lab (src,tit))
428428 modifyIORef picsRef ( (oldsrc, new): )
429429 return new
430430 return $ Image lab (newsrc, tit)
431−transformInline (MathML _) _ _ (x@(Math _ _)) = do
432− -- note: ideally we'd use a switch statement to provide a fallback
433− -- but switch does not seem to be widely implemented yet, so we just
434− -- provide the mathml
435− let result = writeHtmlInline def{writerHTMLMathMethod = MathML Nothing } x
436− return $ RawInline "html" result
431+transformInline opts _ _ (x@(Math _ _))
432+ | WebTeX _ <- writerHTMLMathMethod opts = do
433+ raw <- makeSelfContained Nothing $ writeHtmlInline opts x
434+ return $ RawInline "html" raw
437435transformInline _ _ _ x = return x
438436
439437writeHtmlInline :: WriterOptions -> Inline -> String
440438writeHtmlInline opts z = trimr $
441− writeHtmlString opts $ Pandoc (Meta [] [] []) [Plain [z]]
439+ writeHtmlString opts{ writerStandalone = False }
440+ $ Pandoc (Meta [] [] []) [Plain [z]]
442441
443442(!) :: Node t => (t -> Element) -> [(String, String)] -> t -> Element
444443(!) f attrs n = add_attrs (map (\(k,v) -> Attr (unqual k) v) attrs) (f n)