@@ -42,7 +42,7 @@ import qualified Data.Map as M
42import qualified Data.ByteString.Lazy as BL
42import qualified Data.ByteString.Lazy as BL
43import Data.Monoid (Monoid)
43import Data.Monoid (Monoid)
44import Control.Monad (when, MonadPlus(..))
44import Control.Monad (when, MonadPlus(..))
45−import Text.Pandoc.MIME (getMimeType)
45+import Text.Pandoc.MIME (MimeType, getMimeTypeDef)
46import qualified Text.Pandoc.UTF8 as UTF8
46import qualified Text.Pandoc.UTF8 as UTF8
47import Data.Maybe (fromMaybe)
47import Data.Maybe (fromMaybe)
48import System.IO (stderr)
48import System.IO (stderr)
@@ -51,7 +51,7 @@ import System.IO (stderr)
51-- mime types. Note that a 'MediaBag' is a Monoid, so 'mempty'
51-- mime types. Note that a 'MediaBag' is a Monoid, so 'mempty'
52-- can be used for an empty 'MediaBag', and '<>' can be used to append
52-- can be used for an empty 'MediaBag', and '<>' can be used to append
53-- two 'MediaBag's.
53-- two 'MediaBag's.
54−newtype MediaBag = MediaBag (M.Map String (String, BL.ByteString))
54+newtype MediaBag = MediaBag (M.Map String (MimeType, BL.ByteString))
55 deriving (Monoid)
55 deriving (Monoid)
57instance Show MediaBag where
57instance Show MediaBag where
@@ -59,27 +59,27 @@ instance Show MediaBag where
60-- | Insert a media item into a 'MediaBag', replacing any existing
60-- | Insert a media item into a 'MediaBag', replacing any existing
61-- value with the same name.
61-- value with the same name.
62−insertMedia :: FilePath -- ^ relative path and canonical name of resource
62+insertMedia :: FilePath -- ^ relative path and canonical name of resource
63− -> Maybe String -- ^ mime type (Nothing = determine from extension)
63+ -> Maybe MimeType -- ^ mime type (Nothing = determine from extension)
64− -> BL.ByteString -- ^ contents of resource
64+ -> BL.ByteString -- ^ contents of resource
65 -> MediaBag
65 -> MediaBag
66 -> MediaBag
66 -> MediaBag
67insertMedia fp mbMime contents (MediaBag mediamap) =
67insertMedia fp mbMime contents (MediaBag mediamap) =
68 MediaBag (M.insert fp (mime, contents) mediamap)
68 MediaBag (M.insert fp (mime, contents) mediamap)
69− where mime = fromMaybe "application/octet-stream" (mbMime `mplus` fallback)
69+ where mime = fromMaybe fallback mbMime
70 fallback = case takeExtension fp of
70 fallback = case takeExtension fp of
71− ".gz" -> getMimeType $ dropExtension fp
71+ ".gz" -> getMimeTypeDef $ dropExtension fp
72− _ -> getMimeType fp
72+ _ -> getMimeTypeDef fp
74-- | Lookup a media item in a 'MediaBag', returning mime type and contents.
74-- | Lookup a media item in a 'MediaBag', returning mime type and contents.
75lookupMedia :: FilePath
75lookupMedia :: FilePath
76 -> MediaBag
76 -> MediaBag
77− -> Maybe (String, BL.ByteString)
77+ -> Maybe (MimeType, BL.ByteString)
78lookupMedia fp (MediaBag mediamap) = M.lookup fp mediamap
78lookupMedia fp (MediaBag mediamap) = M.lookup fp mediamap
80-- | Get a list of the file paths stored in a 'MediaBag', with
80-- | Get a list of the file paths stored in a 'MediaBag', with
81-- their corresponding mime types and the lengths in bytes of the contents.
81-- their corresponding mime types and the lengths in bytes of the contents.
82−mediaDirectory :: MediaBag -> [(String, String, Int)]
82+mediaDirectory :: MediaBag -> [(String, MimeType, Int)]
83mediaDirectory (MediaBag mediamap) =
83mediaDirectory (MediaBag mediamap) =
84 M.foldWithKey (\fp (mime,contents) ->
84 M.foldWithKey (\fp (mime,contents) ->
85 ((fp, mime, fromIntegral $ BL.length contents):)) [] mediamap
85 ((fp, mime, fromIntegral $ BL.length contents):)) [] mediamap