From 77d9ead1b211a87aea8816f86040d269b24671c3 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 11 Jan 2013 11:30:31 -0800 Subject: Move getItem from SelfContained to Share; export getItem. --- src/Text/Pandoc/SelfContained.hs | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) (limited to 'src/Text/Pandoc/SelfContained.hs') diff --git a/src/Text/Pandoc/SelfContained.hs b/src/Text/Pandoc/SelfContained.hs index 4b52a6f13..c02e61ba9 100644 --- a/src/Text/Pandoc/SelfContained.hs +++ b/src/Text/Pandoc/SelfContained.hs @@ -32,42 +32,17 @@ the HTML using data URIs. -} module Text.Pandoc.SelfContained ( makeSelfContained ) where import Text.HTML.TagSoup -import Network.URI (isAbsoluteURI, parseURI, escapeURIString) -import Network.HTTP +import Network.URI (isAbsoluteURI, escapeURIString) import Data.ByteString.Base64 import qualified Data.ByteString.Char8 as B import Data.ByteString (ByteString) -import System.FilePath (takeExtension, dropExtension, takeDirectory, ()) +import System.FilePath (takeExtension, takeDirectory, ()) import Data.Char (toLower, isAscii, isAlphaNum) import Codec.Compression.GZip as Gzip import qualified Data.ByteString.Lazy as L -import Text.Pandoc.Shared (readDataFile, renderTags') -import Text.Pandoc.MIME (getMimeType) -import System.Directory (doesFileExist) +import Text.Pandoc.Shared (renderTags', getItem) import Text.Pandoc.UTF8 (toString, fromString) -getItem :: Maybe FilePath -> String -> IO (ByteString, Maybe String) -getItem userdata f = - if isAbsoluteURI f - then openURL f - else do - let mime = case takeExtension f of - ".gz" -> getMimeType $ dropExtension f - x -> getMimeType x - exists <- doesFileExist f - cont <- if exists then B.readFile f else readDataFile userdata f - return (cont, mime) - --- TODO - have this return mime type too - then it can work for google --- chart API, e.g. -openURL :: String -> IO (ByteString, Maybe String) -openURL u = getBodyAndMimeType =<< simpleHTTP (getReq u) - where getReq v = case parseURI v of - Nothing -> error $ "Could not parse URI: " ++ v - Just u' -> mkRequest GET u' - getBodyAndMimeType (Left err) = fail (show err) - getBodyAndMimeType (Right r) = return (rspBody r, findHeader HdrContentType r) - isOk :: Char -> Bool isOk c = isAscii c && isAlphaNum c -- cgit v1.2.3