@@ -37,8 +37,8 @@ import Text.Pandoc.Readers.Org.BlockStarts
3737import Text.Pandoc.Readers.Org.ParserState
3838import Text.Pandoc.Readers.Org.Parsing
3939import Text.Pandoc.Readers.Org.Shared
40− ( isImageFilename, rundocBlockClass, toRundocAttrib
41− , translateLang )
40+ ( cleanLinkString, isImageFilename, rundocBlockClass
41+ , toRundocAttrib, translateLang )
4242
4343import qualified Text.Pandoc.Builder as B
4444import Text.Pandoc.Builder ( Inlines )
@@ -52,7 +52,7 @@ import qualified Text.TeXMath.Readers.MathML.EntityMap as MathMLEntityMap
5252import Prelude hiding (sequence)
5353import Control.Monad ( guard, mplus, mzero, when, void )
5454import Data.Char ( isAlphaNum, isSpace )
55−import Data.List ( intersperse, isPrefixOf )
55+import Data.List ( intersperse )
5656import Data.Maybe ( fromMaybe )
5757import qualified Data.Map as M
5858import Data.Traversable (sequence)
@@ -435,9 +435,11 @@ explicitOrImageLink = try $ do
435435 char ']'
436436 return $ do
437437 src <- srcF
438− if isImageFilename title
439− then pure $ B.link src "" $ B.image title mempty mempty
440− else linkToInlinesF src =<< title'
438+ case cleanLinkString title of
439+ Just imgSrc | isImageFilename imgSrc ->
440+ pure $ B.link src "" $ B.image imgSrc mempty mempty
441+ _ ->
442+ linkToInlinesF src =<< title'
441443
442444selflinkOrImage :: OrgParser (F Inlines)
443445selflinkOrImage = try $ do
@@ -482,25 +484,6 @@ linkToInlinesF linkStr =
482484 else pure . B.link cleanedLink ""
483485 Nothing -> internalLink linkStr -- other internal link
484486
485−-- | Cleanup and canonicalize a string describing a link. Return @Nothing@ if
486−-- the string does not appear to be a link.
487−cleanLinkString :: String -> Maybe String
488−cleanLinkString s =
489− case s of
490− '/':_ -> Just $ "file://" ++ s -- absolute path
491− '.':'/':_ -> Just s -- relative path
492− '.':'.':'/':_ -> Just s -- relative path
493− -- Relative path or URL (file schema)
494− 'f':'i':'l':'e':':':s' -> Just $ if ("//" `isPrefixOf` s') then s else s'
495− _ | isUrl s -> Just s -- URL
496− _ -> Nothing
497− where
498− isUrl :: String -> Bool
499− isUrl cs =
500− let (scheme, path) = break (== ':') cs
501− in all (\c -> isAlphaNum c || c `elem` (".-"::String)) scheme
502− && not (null path)
503−
504487internalLink :: String -> Inlines -> F Inlines
505488internalLink link title = do
506489 anchorB <- (link `elem`) <$> asksF orgStateAnchorIds