aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/MIME.hs
diff options
context:
space:
mode:
authormb21 <mb21@users.noreply.github.com>2019-05-11 18:13:37 +0200
committermb21 <mb21@users.noreply.github.com>2019-05-29 09:42:28 +0200
commit47249b05c4345a40353a37f4b7f7170aa2ea5773 (patch)
tree45c2e13a699d293764d442a31ef0f548326b040f /src/Text/Pandoc/MIME.hs
parent2ad5dacf876a308e267801db315c12deec39bb5e (diff)
downloadpandoc-47249b05c4345a40353a37f4b7f7170aa2ea5773.tar.gz
Text.Pandoc.MIME: add mediaCategory [API change]
Diffstat (limited to 'src/Text/Pandoc/MIME.hs')
-rw-r--r--src/Text/Pandoc/MIME.hs11
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