mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-21 13:51:29 +08:00
T.P.MIME, extensionFromMimeType: add a few special cases.
When we do a reverse lookup in the MIME table, we just get the last match, so when the same mime type is associated with several different extensions, we sometimes got weird results, e.g. `.vs` for `text/plain`. These special cases help us get the most standard extensions for mime types like `text/plain`.
This commit is contained in:
@@ -43,6 +43,16 @@ getMimeTypeDef :: FilePath -> MimeType
|
||||
getMimeTypeDef = fromMaybe "application/octet-stream" . getMimeType
|
||||
|
||||
extensionFromMimeType :: MimeType -> Maybe T.Text
|
||||
-- few special cases, where there are multiple options:
|
||||
extensionFromMimeType "text/plain" = Just "txt"
|
||||
extensionFromMimeType "video/quicktime" = Just "mov"
|
||||
extensionFromMimeType "video/mpeg" = Just "mpeg"
|
||||
extensionFromMimeType "video/dv" = Just "dv"
|
||||
extensionFromMimeType "image/vnd.djvu" = Just "djvu"
|
||||
extensionFromMimeType "image/tiff" = Just "tiff"
|
||||
extensionFromMimeType "image/jpeg" = Just "jpg"
|
||||
extensionFromMimeType "application/xml" = Just "xml"
|
||||
extensionFromMimeType "application/ogg" = Just "ogg"
|
||||
extensionFromMimeType mimetype =
|
||||
M.lookup (T.takeWhile (/=';') mimetype) reverseMimeTypes
|
||||
-- note: we just look up the basic mime type, dropping the content-encoding etc.
|
||||
|
||||
Reference in New Issue
Block a user