aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/Org/Inlines.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/Readers/Org/Inlines.hs')
-rw-r--r--src/Text/Pandoc/Readers/Org/Inlines.hs31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Readers/Org/Inlines.hs b/src/Text/Pandoc/Readers/Org/Inlines.hs
index dfe398130..6560def7e 100644
--- a/src/Text/Pandoc/Readers/Org/Inlines.hs
+++ b/src/Text/Pandoc/Readers/Org/Inlines.hs
@@ -432,21 +432,28 @@ 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 -> case target of
+ '#':_ -> returnF $ B.link target "" (B.str target)
+ _ -> return $ internalLink target (B.str target)
+ Just nonDocTgt -> if isImageFilename nonDocTgt
+ then returnF $ B.image nonDocTgt "" ""
+ else returnF $ B.link nonDocTgt "" (B.str target)
plainLink :: PandocMonad m => OrgParser m (F Inlines)
plainLink = try $ do
@@ -481,10 +488,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
@@ -530,7 +535,7 @@ inlineCodeBlock = try $ do
let attrClasses = [translateLang lang]
let attrKeyVal = originalLang lang <> opts
let codeInlineBlck = B.codeWith ("", attrClasses, attrKeyVal) inlineCode
- returnF $ (if exportsCode opts then codeInlineBlck else mempty)
+ returnF $ if exportsCode opts then codeInlineBlck else mempty
where
inlineBlockOption :: PandocMonad m => OrgParser m (String, String)
inlineBlockOption = try $ do
@@ -739,7 +744,7 @@ many1TillNOrLessNewlines n p end = try $
rest m cs = (\x -> (minus1 <$> m, cs ++ x ++ "\n")) <$> try (manyTill p newline)
finalLine = try $ manyTill p end
minus1 k = k - 1
- oneOrMore cs = guard (not $ null cs) *> return cs
+ oneOrMore cs = cs <$ guard (not $ null cs)
-- Org allows customization of the way it reads emphasis. We use the defaults
-- here (see, e.g., the Emacs Lisp variable `org-emphasis-regexp-components`