aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2014-08-02 16:32:11 -0700
committerJohn MacFarlane <fiddlosopher@gmail.com>2014-08-02 16:32:11 -0700
commit85ff3c57710dc96e4f7e80b51d85f93bffca8a3b (patch)
tree11b8892d82e81decb7162fc5b9a59e8f4470af2c /src/Text
parent1d137fbed69a61e751e94539b51a2aad0618026d (diff)
downloadpandoc-85ff3c57710dc96e4f7e80b51d85f93bffca8a3b.tar.gz
fetchItem: improved mime type guessing.
Strip a fragment like `?#iefix` from the extension before doing the mime lookup.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Shared.hs9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index df788425b..9acb959a0 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -775,12 +775,13 @@ fetchItem sourceURL s =
Nothing -> openURL s' -- will throw error
(Nothing, _) -> E.try readLocalFile -- get from local file system
where readLocalFile = do
- let mime = case takeExtension s of
- ".gz" -> getMimeType $ dropExtension s
- x -> getMimeType x
- cont <- BS.readFile $ unEscapeString $ dropFragmentAndQuery s
+ cont <- BS.readFile fp
return (cont, mime)
dropFragmentAndQuery = takeWhile (\c -> c /= '?' && c /= '#')
+ fp = unEscapeString $ dropFragmentAndQuery s
+ mime = case takeExtension fp of
+ ".gz" -> getMimeType $ dropExtension fp
+ x -> getMimeType x
ensureEscaped = escapeURIString isAllowedInURI
-- | Like 'fetchItem', but also looks for items in a 'MediaBag'.