Shared: Added fetchItem', which searches a media bag too.
This commit is contained in:
parent
67c5c7a575
commit
28321a18bf
1 changed files with 14 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue