aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorAlbert Krewinkel <albert@zeitkraut.de>2019-01-01 20:53:52 +0100
committerAlbert Krewinkel <albert@zeitkraut.de>2019-01-01 21:03:38 +0100
commitc0caaaeabb3646d6156a0857e250969b4244cdc5 (patch)
tree0f2c65327954685d5a8b09ce0c15ce33b9d060fd /src/Text/Pandoc/Readers
parentaf887e9198b2192daac4827923ea319892ad5bdd (diff)
downloadpandoc-c0caaaeabb3646d6156a0857e250969b4244cdc5.tar.gz
Org reader: fix treatment of links to images
Links with descriptions which are pointing to images are no longer read as inline images, but as proper links. Fixes: #5191
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/Org/Inlines.hs26
-rw-r--r--src/Text/Pandoc/Readers/Org/Shared.hs3
2 files changed, 16 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Inlines.hs b/src/Text/Pandoc/Readers/Org/Inlines.hs
index b5b2b5c47..b8aee0322 100644
--- a/src/Text/Pandoc/Readers/Org/Inlines.hs
+++ b/src/Text/Pandoc/Readers/Org/Inlines.hs
@@ -432,21 +432,27 @@ explicitOrImageLink :: PandocMonad m => OrgParser m (F Inlines)
explicitOrImageLink = try $ do
char '['
srcF <- applyCustomLinkFormat =<< possiblyEmptyLinkTarget
- title <- enclosedRaw (char '[') (char ']')
- title' <- parseFromString (mconcat <$> many inline) title
+ descr <- enclosedRaw (char '[') (char ']')
+ titleF <- parseFromString (mconcat <$> many inline) descr
char ']'
return $ do
src <- srcF
- case cleanLinkString title of
+ title <- titleF
+ case cleanLinkString descr of
Just imgSrc | isImageFilename imgSrc ->
- pure . B.link src "" $ B.image imgSrc mempty mempty
+ return . B.link src "" $ B.image imgSrc mempty mempty
_ ->
- linkToInlinesF src =<< title'
+ linkToInlinesF src title
selflinkOrImage :: PandocMonad m => OrgParser m (F Inlines)
selflinkOrImage = try $ do
- src <- char '[' *> linkTarget <* char ']'
- return $ linkToInlinesF src (B.str src)
+ target <- char '[' *> linkTarget <* char ']'
+ case cleanLinkString target of
+ Nothing -> return $ internalLink target (B.str target)
+ Just nonDocTgt -> returnF $
+ if isImageFilename nonDocTgt
+ then B.image nonDocTgt "" ""
+ else B.link nonDocTgt "" (B.str target)
plainLink :: PandocMonad m => OrgParser m (F Inlines)
plainLink = try $ do
@@ -481,10 +487,8 @@ linkToInlinesF linkStr =
"" -> pure . B.link mempty "" -- wiki link (empty by convention)
('#':_) -> pure . B.link linkStr "" -- document-local fraction
_ -> case cleanLinkString linkStr of
- (Just cleanedLink) -> if isImageFilename cleanedLink
- then const . pure $ B.image cleanedLink "" ""
- else pure . B.link cleanedLink ""
- Nothing -> internalLink linkStr -- other internal link
+ Just extTgt -> return . B.link extTgt ""
+ Nothing -> internalLink linkStr -- other internal link
internalLink :: String -> Inlines -> F Inlines
internalLink link title = do
diff --git a/src/Text/Pandoc/Readers/Org/Shared.hs b/src/Text/Pandoc/Readers/Org/Shared.hs
index 71d1dd517..9e7ef9930 100644
--- a/src/Text/Pandoc/Readers/Org/Shared.hs
+++ b/src/Text/Pandoc/Readers/Org/Shared.hs
@@ -61,8 +61,7 @@ cleanLinkString s =
'.':'.':'/':_ -> Just s -- relative path
-- Relative path or URL (file schema)
'f':'i':'l':'e':':':s' -> Just $ if "//" `isPrefixOf` s' then s else s'
- _ | isUrl s -> Just s -- URL
- _ -> Nothing
+ _ -> if isUrl s then Just s else Nothing
where
isUrl :: String -> Bool
isUrl cs =