@@ -89,7 +89,7 @@ import Data.Char ( toLower, isLower, isUpper, isAlpha,
8989 isLetter, isDigit, isSpace )
9090import Data.List ( find, isPrefixOf, intercalate )
9191import qualified Data.Map as M
92−import Network.URI ( escapeURIString, isAbsoluteURI, parseURI, unEscapeString )
92+import Network.URI ( escapeURIString, isAbsoluteURI, unEscapeString )
9393import System.Directory
9494import Text.Pandoc.MIME (getMimeType)
9595import System.FilePath ( (</>), takeExtension, dropExtension )
@@ -102,11 +102,9 @@ import Data.Time
102102import System.IO (stderr)
103103import Text.HTML.TagSoup (renderTagsOptions, RenderOptions(..), Tag(..),
104104 renderOptions)
105−import qualified Data.ByteString as B
105+import qualified Data.ByteString as BS
106+import Data.ByteString.Lazy (toChunks)
106107import qualified Data.ByteString.Char8 as B8
107−import Network.HTTP (findHeader, rspBody,
108− RequestMethod(..), HeaderName(..), mkRequest)
109−import Network.Browser (browse, setAllowRedirects, setOutHandler, request)
110108
111109#ifdef EMBED_DATA_FILES
112110import Text.Pandoc.Data (dataFiles)
@@ -114,6 +112,16 @@ import System.FilePath ( joinPath, splitDirectories )
114112#else
115113import Paths_pandoc (getDataFileName)
116114#endif
115+#ifdef HTTP_CONDUIT
116+import Network.HTTP.Conduit (httpLbs, parseUrl, withManager,
117+ responseBody, responseHeaders)
118+import Network.HTTP.Types.Header ( hContentType)
119+#else
120+import Network.URI (parseURI)
121+import Network.HTTP (findHeader, rspBody,
122+ RequestMethod(..), HeaderName(..), mkRequest)
123+import Network.Browser (browse, setAllowRedirects, setOutHandler, request)
124+#endif
117125
118126--
119127-- List processing
@@ -545,7 +553,7 @@ inDirectory path action = do
545553 setCurrentDirectory oldDir
546554 return result
547555
548−readDefaultDataFile :: FilePath -> IO B.ByteString
556+readDefaultDataFile :: FilePath -> IO BS.ByteString
549557readDefaultDataFile fname =
550558#ifdef EMBED_DATA_FILES
551559 case lookup (makeCanonical fname) dataFiles of
@@ -558,17 +566,17 @@ readDefaultDataFile fname =
558566 go (_:as) ".." = as
559567 go as x = x : as
560568#else
561− getDataFileName ("data" </> fname) >>= B.readFile
569+ getDataFileName ("data" </> fname) >>= BS.readFile
562570#endif
563571
564572-- | Read file from specified user data directory or, if not found there, from
565573-- Cabal data directory.
566−readDataFile :: Maybe FilePath -> FilePath -> IO B.ByteString
574+readDataFile :: Maybe FilePath -> FilePath -> IO BS.ByteString
567575readDataFile Nothing fname = readDefaultDataFile fname
568576readDataFile (Just userDir) fname = do
569577 exists <- doesFileExist (userDir </> fname)
570578 if exists
571− then B.readFile (userDir </> fname)
579+ then BS.readFile (userDir </> fname)
572580 else readDefaultDataFile fname
573581
574582-- | Same as 'readDataFile' but returns a String instead of a ByteString.
@@ -578,7 +586,7 @@ readDataFileUTF8 userDir fname =
578586
579587-- | Fetch an image or other item from the local filesystem or the net.
580588-- Returns raw content and maybe mime type.
581−fetchItem :: String -> String -> IO (B.ByteString, Maybe String)
589+fetchItem :: String -> String -> IO (BS.ByteString, Maybe String)
582590fetchItem sourceDir s =
583591 case s of
584592 _ | isAbsoluteURI s -> openURL s
@@ -588,16 +596,23 @@ fetchItem sourceDir s =
588596 ".gz" -> getMimeType $ dropExtension s
589597 x -> getMimeType x
590598 let f = sourceDir </> s
591− cont <- B.readFile f
599+ cont <- BS.readFile f
592600 return (cont, mime)
593601
594602-- | Read from a URL and return raw data and maybe mime type.
595−openURL :: String -> IO (B.ByteString, Maybe String)
603+openURL :: String -> IO (BS.ByteString, Maybe String)
596604openURL u
597605 | "data:" `isPrefixOf` u =
598606 let mime = takeWhile (/=',') $ drop 5 u
599607 contents = B8.pack $ unEscapeString $ drop 1 $ dropWhile (/=',') u
600608 in return (contents, Just mime)
609+#ifdef HTTP_CONDUIT
610+ | otherwise = do
611+ req <- parseUrl u
612+ resp <- withManager $ httpLbs req
613+ return (BS.concat $ toChunks $ responseBody resp,
614+ UTF8.toString `fmap` lookup hContentType (responseHeaders resp))
615+#else
601616 | otherwise = getBodyAndMimeType `fmap` browse
602617 (do S.liftIO $ UTF8.hPutStrLn stderr $ "Fetching " ++ u ++ "..."
603618 setOutHandler $ const (return ())
@@ -609,6 +624,7 @@ openURL u
609624 uriString)
610625 Just v -> mkRequest GET v
611626 u' = escapeURIString (/= '|') u -- pipes are rejected by Network.URI
627+#endif
612628
613629--
614630-- Error reporting