summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/Shared.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index d296888d6..53f20f232 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -79,6 +79,7 @@ module Text.Pandoc.Shared (
readDataFile,
readDataFileUTF8,
fetchItem,
+ fetchItem',
openURL,
-- * Error handling
err,
@@ -791,6 +792,19 @@ fetchItem sourceURL s
cont <- BS.readFile $ unEscapeString s
return (cont, mime)
+-- | Like 'fetchItem', but also looks for items in a 'MediaBag'.
+fetchItem' :: Maybe MediaBag -> Maybe String -> String
+ -> IO (Either E.SomeException (BS.ByteString, Maybe String))
+fetchItem' Nothing sourceURL s = fetchItem sourceURL s
+fetchItem' (Just media) sourceURL s = do
+ case M.lookup s media of
+ Nothing -> fetchItem sourceURL s
+ Just bs -> do
+ let mime = case takeExtension s of
+ ".gz" -> getMimeType $ dropExtension s
+ x -> getMimeType x
+ return $ Right (BS.concat $ toChunks bs, mime)
+
-- | Read from a URL and return raw data and maybe mime type.
openURL :: String -> IO (Either E.SomeException (BS.ByteString, Maybe String))
openURL u