diff options
author | Yan Pas <yanp.bugz@gmail.com> | 2018-05-12 11:42:39 +0300 |
---|---|---|
committer | Yan Pas <yanp.bugz@gmail.com> | 2018-05-12 11:42:39 +0300 |
commit | b0b41cbbe6e316d63f196d8043b636a9050376fc (patch) | |
tree | 1226053cabecb78399fdc1bc3f28a224e55d34ba /src/Text/Pandoc/Readers | |
parent | ad19166bc308a2428bd040851a2a97c76e8873f9 (diff) | |
parent | a00ca6f0d8e83821d9be910f1eebf3d3cdd1170f (diff) | |
download | pandoc-b0b41cbbe6e316d63f196d8043b636a9050376fc.tar.gz |
Merge branch 'master' into groff_reader
Diffstat (limited to 'src/Text/Pandoc/Readers')
-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 |