Text.Pandoc.MIME: add exported function getCharset.
[API change]
This commit is contained in:
parent
80fde18fb1
commit
4617f229ea
1 changed files with 15 additions and 2 deletions
|
@ -10,8 +10,13 @@
|
|||
|
||||
Mime type lookup.
|
||||
-}
|
||||
module Text.Pandoc.MIME ( MimeType, getMimeType, getMimeTypeDef,
|
||||
extensionFromMimeType, mediaCategory ) where
|
||||
module Text.Pandoc.MIME (
|
||||
MimeType,
|
||||
getMimeType,
|
||||
getMimeTypeDef,
|
||||
getCharset,
|
||||
extensionFromMimeType,
|
||||
mediaCategory ) where
|
||||
import Data.List (isPrefixOf, isSuffixOf)
|
||||
import qualified Data.Map as M
|
||||
import qualified Data.Text as T
|
||||
|
@ -54,6 +59,14 @@ reverseMimeTypes = M.fromList $ map swap mimeTypesList
|
|||
mimeTypes :: M.Map T.Text MimeType
|
||||
mimeTypes = M.fromList mimeTypesList
|
||||
|
||||
-- | Get the charset from a mime type, if one is present.
|
||||
getCharset :: MimeType -> Maybe T.Text
|
||||
getCharset mt =
|
||||
let (_,y) = T.breakOn "charset=" mt
|
||||
in if T.null y
|
||||
then Nothing
|
||||
else Just $ T.toUpper $ T.takeWhile (/= ';') $ T.drop 8 y
|
||||
|
||||
-- | Collection of common mime types.
|
||||
-- Except for first entry, list borrowed from
|
||||
-- <https://github.com/Happstack/happstack-server/blob/master/src/Happstack/Server/FileServe/BuildingBlocks.hs happstack-server>
|
||||
|
|
Loading…
Add table
Reference in a new issue