diff options
| author | John MacFarlane <[email protected]> | 2024-12-19 13:08:25 -0800 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-12-19 13:08:25 -0800 |
| commit | 3900791a0f747aa42e017152cdca67127d9f8133 (patch) | |
| tree | 34575d79979c3e78a36cac8b72de69be7f7a6864 /src | |
| parent | df0d3fb78cd5d0457c791bbd3b132dd284bfe49c (diff) | |
T.P.MIME: fix `extensionFromMimeType`.
We had a few special cases encoded, but as previously written
they wouldn't work properly with modifiers like `;charset=utf-8`.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/MIME.hs | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/src/Text/Pandoc/MIME.hs b/src/Text/Pandoc/MIME.hs index b6aae1092..9104f36b3 100644 --- a/src/Text/Pandoc/MIME.hs +++ b/src/Text/Pandoc/MIME.hs @@ -45,20 +45,21 @@ 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 "image/svg+xml" = Just "svg" -- avoid svgz extensionFromMimeType mimetype = - M.lookup (T.takeWhile (/=';') mimetype) reverseMimeTypes -- note: we just look up the basic mime type, dropping the content-encoding etc. + case T.takeWhile (/=';') mimetype of + -- handle a few special cases, where there are multiple options: + "text/plain" -> Just "txt" + "video/quicktime" -> Just "mov" + "video/mpeg" -> Just "mpeg" + "video/dv" -> Just "dv" + "image/vnd.djvu" -> Just "djvu" + "image/tiff" -> Just "tiff" + "image/jpeg" -> Just "jpg" + "application/xml" -> Just "xml" + "application/ogg" -> Just "ogg" + "image/svg+xml" -> Just "svg" -- avoid svgz + mt -> M.lookup mt reverseMimeTypes -- | Determine general media category for file path, e.g. -- |
