aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-01-08 09:52:39 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-01-08 09:52:39 -0800
commit0ee49911f65ec70bbfe81da2d2eeba5ae1d81f18 (patch)
treee035ce5670f28fc051e76443981ff8f86eeddd2b /src/Text/Pandoc/Readers
parentd850712f991d5d3c8555360f239de2cfdea083b6 (diff)
downloadpandoc-0ee49911f65ec70bbfe81da2d2eeba5ae1d81f18.tar.gz
Markdown reader: Allow links in image captions.
This change also means that [link with [link](/url)](/url) will turn into <p><a href="/url">link with link</a></p> instead of <p><a href="/url">link with [link](/url)</a></p>
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs23
1 files changed, 10 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 9f6609c6d..be6e9c700 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -936,15 +936,6 @@ inlineParsers = [ whitespace
, symbol
, ltSign ]
-inlineNonLink :: GenParser Char ParserState Inline
-inlineNonLink = (choice $
- map (\parser -> try (parser >>= failIfLink)) inlineParsers)
- <?> "inline (non-link)"
-
-failIfLink :: Inline -> GenParser tok st Inline
-failIfLink (Link _ _) = pzero
-failIfLink elt = return elt
-
escapedChar' :: GenParser Char ParserState Char
escapedChar' = try $ do
char '\\'
@@ -1146,7 +1137,7 @@ endline = try $ do
-- a reference label for a link
reference :: GenParser Char ParserState [Inline]
reference = do notFollowedBy' (string "[^") -- footnote reference
- result <- inlinesInBalancedBrackets inlineNonLink
+ result <- inlinesInBalancedBrackets inline
return $ normalizeSpaces result
-- source for a link, with optional title
@@ -1187,7 +1178,12 @@ link :: GenParser Char ParserState Inline
link = try $ do
lab <- reference
(src, tit) <- source <|> referenceLink lab
- return $ Link lab (src, tit)
+ return $ Link (delinkify lab) (src, tit)
+
+delinkify :: [Inline] -> [Inline]
+delinkify = bottomUp $ concatMap go
+ where go (Link lab _) = lab
+ go x = [x]
-- a link like [this][ref] or [this][] or [this]
referenceLink :: [Inline]
@@ -1214,8 +1210,9 @@ autoLink = try $ do
image :: GenParser Char ParserState Inline
image = try $ do
char '!'
- (Link lab src) <- link
- return $ Image lab src
+ lab <- reference
+ (src, tit) <- source <|> referenceLink lab
+ return $ Image lab (src,tit)
note :: GenParser Char ParserState Inline
note = try $ do