@@ -42,7 +42,7 @@ import qualified Data.Map as M
4242import qualified Data.ByteString.Lazy as BL
4343import Data.Monoid (Monoid)
4444import Control.Monad (when, MonadPlus(..))
45−import Text.Pandoc.MIME (getMimeType)
45+import Text.Pandoc.MIME (MimeType, getMimeTypeDef)
4646import qualified Text.Pandoc.UTF8 as UTF8
4747import Data.Maybe (fromMaybe)
4848import System.IO (stderr)
@@ -51,7 +51,7 @@ import System.IO (stderr)
5151-- mime types. Note that a 'MediaBag' is a Monoid, so 'mempty'
5252-- can be used for an empty 'MediaBag', and '<>' can be used to append
5353-- two 'MediaBag's.
54−newtype MediaBag = MediaBag (M.Map String (String, BL.ByteString))
54+newtype MediaBag = MediaBag (M.Map String (MimeType, BL.ByteString))
5555 deriving (Monoid)
5656
5757instance Show MediaBag where
@@ -59,27 +59,27 @@ instance Show MediaBag where
5959
6060-- | Insert a media item into a 'MediaBag', replacing any existing
6161-- value with the same name.
62−insertMedia :: FilePath -- ^ relative path and canonical name of resource
63− -> Maybe String -- ^ mime type (Nothing = determine from extension)
64− -> BL.ByteString -- ^ contents of resource
62+insertMedia :: FilePath -- ^ relative path and canonical name of resource
63+ -> Maybe MimeType -- ^ mime type (Nothing = determine from extension)
64+ -> BL.ByteString -- ^ contents of resource
6565 -> MediaBag
6666 -> MediaBag
6767insertMedia fp mbMime contents (MediaBag mediamap) =
6868 MediaBag (M.insert fp (mime, contents) mediamap)
69− where mime = fromMaybe "application/octet-stream" (mbMime `mplus` fallback)
69+ where mime = fromMaybe fallback mbMime
7070 fallback = case takeExtension fp of
71− ".gz" -> getMimeType $ dropExtension fp
72− _ -> getMimeType fp
71+ ".gz" -> getMimeTypeDef $ dropExtension fp
72+ _ -> getMimeTypeDef fp
7373
7474-- | Lookup a media item in a 'MediaBag', returning mime type and contents.
7575lookupMedia :: FilePath
7676 -> MediaBag
77− -> Maybe (String, BL.ByteString)
77+ -> Maybe (MimeType, BL.ByteString)
7878lookupMedia fp (MediaBag mediamap) = M.lookup fp mediamap
7979
8080-- | Get a list of the file paths stored in a 'MediaBag', with
8181-- their corresponding mime types and the lengths in bytes of the contents.
82−mediaDirectory :: MediaBag -> [(String, String, Int)]
82+mediaDirectory :: MediaBag -> [(String, MimeType, Int)]
8383mediaDirectory (MediaBag mediamap) =
8484 M.foldWithKey (\fp (mime,contents) ->
8585 ((fp, mime, fromIntegral $ BL.length contents):)) [] mediamap