diff options
author | Albert Krewinkel <albert@zeitkraut.de> | 2018-05-09 23:03:09 +0200 |
---|---|---|
committer | Albert Krewinkel <albert@zeitkraut.de> | 2018-05-09 23:08:53 +0200 |
commit | d30fbc2879f58be7951eeb1cf8f9acfc83f1ebe6 (patch) | |
tree | 3214f686d82e97e2e9df977bf20336db9b5909c3 | |
parent | 0eee6368d32948f504b827d6b5130d2d441cee8e (diff) | |
download | pandoc-d30fbc2879f58be7951eeb1cf8f9acfc83f1ebe6.tar.gz |
Org reader: fix image filename recognition
Use a function from the *filepath* library to check whether a string is
a valid file name. The custom validity checker that was used before gave
wrong results, e.g. for absolute file paths on
Windows (kawabata/ox-pandoc#52).
-rw-r--r-- | src/Text/Pandoc/Readers/Org/Shared.hs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Shared.hs b/src/Text/Pandoc/Readers/Org/Shared.hs index 07dbeca2a..17fe34738 100644 --- a/src/Text/Pandoc/Readers/Org/Shared.hs +++ b/src/Text/Pandoc/Readers/Org/Shared.hs @@ -36,17 +36,18 @@ module Text.Pandoc.Readers.Org.Shared import Prelude import Data.Char (isAlphaNum) -import Data.List (isPrefixOf, isSuffixOf) +import Data.List (isPrefixOf) +import System.FilePath (isValid, takeExtension) -- | Check whether the given string looks like the path to of URL of an image. isImageFilename :: String -> Bool -isImageFilename filename = - any (\x -> ('.':x) `isSuffixOf` filename) imageExtensions && - (any (\x -> (x ++ "://") `isPrefixOf` filename) protocols || - ':' `notElem` filename) +isImageFilename fp = hasImageExtension && (isValid fp || isKnownProtocolUri) where - imageExtensions = [ "jpeg" , "jpg" , "png" , "gif" , "svg" ] + hasImageExtension = takeExtension fp `elem` imageExtensions + isKnownProtocolUri = any (\x -> (x ++ "://") `isPrefixOf` fp) protocols + + imageExtensions = [ ".jpeg", ".jpg", ".png", ".gif", ".svg" ] protocols = [ "file", "http", "https" ] -- | Cleanup and canonicalize a string describing a link. Return @Nothing@ if |