diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/MIME.hs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/Text/Pandoc/MIME.hs b/src/Text/Pandoc/MIME.hs index 19488c9bc..767362d49 100644 --- a/src/Text/Pandoc/MIME.hs +++ b/src/Text/Pandoc/MIME.hs @@ -11,12 +11,13 @@ Mime type lookup for ODT writer. -} module Text.Pandoc.MIME ( MimeType, getMimeType, getMimeTypeDef, - extensionFromMimeType )where + extensionFromMimeType, mediaCategory ) where import Prelude import Data.Char (toLower) import Data.List (isPrefixOf, isSuffixOf) +import Data.List.Split (splitOn) import qualified Data.Map as M -import Data.Maybe (fromMaybe) +import Data.Maybe (fromMaybe, listToMaybe) import System.FilePath type MimeType = String @@ -42,6 +43,12 @@ extensionFromMimeType mimetype = M.lookup (takeWhile (/=';') mimetype) reverseMimeTypes -- note: we just look up the basic mime type, dropping the content-encoding etc. +-- | Determine general media category for file path, e.g. +-- +-- prop> mediaCategory "foo.jpg" = Just "image" +mediaCategory :: FilePath -> Maybe String +mediaCategory fp = getMimeType fp >>= listToMaybe . splitOn "/" + reverseMimeTypes :: M.Map MimeType String reverseMimeTypes = M.fromList $ map (\(k,v) -> (v,k)) mimeTypesList |