git.iko.soy/typeable/pandoc
on master help sign in
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>

commit0ee49911f65ec70bbfe81da2d2eeba5ae1d81f18 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSun 8 Jan 2012, 09:52 (15 years ago) parentd850712
1 file changed+10−13
src/Text/Pandoc/Readers/Markdown.hs+10−13
src/Text/Pandoc/Readers/Markdown.hs+10−13
@@ -936,15 +936,6 @@ inlineParsers = [ whitespace
936936 , symbol
937937 , ltSign ]
938938
939−inlineNonLink :: GenParser Char ParserState Inline
940−inlineNonLink = (choice $
941− map (\parser -> try (parser >>= failIfLink)) inlineParsers)
942− <?> "inline (non-link)"
943−
944−failIfLink :: Inline -> GenParser tok st Inline
945−failIfLink (Link _ _) = pzero
946−failIfLink elt = return elt
947−
948939escapedChar' :: GenParser Char ParserState Char
949940escapedChar' = try $ do
950941 char '\\'
@@ -1146,7 +1137,7 @@ endline = try $ do
11461137-- a reference label for a link
11471138reference :: GenParser Char ParserState [Inline]
11481139reference = do notFollowedBy' (string "[^") -- footnote reference
1149− result <- inlinesInBalancedBrackets inlineNonLink
1140+ result <- inlinesInBalancedBrackets inline
11501141 return $ normalizeSpaces result
11511142
11521143-- source for a link, with optional title
@@ -1187,7 +1178,12 @@ link :: GenParser Char ParserState Inline
11871178link = try $ do
11881179 lab <- reference
11891180 (src, tit) <- source <|> referenceLink lab
1190− return $ Link lab (src, tit)
1181+ return $ Link (delinkify lab) (src, tit)
1182+
1183+delinkify :: [Inline] -> [Inline]
1184+delinkify = bottomUp $ concatMap go
1185+ where go (Link lab _) = lab
1186+ go x = [x]
11911187
11921188-- a link like [this][ref] or [this][] or [this]
11931189referenceLink :: [Inline]
@@ -1214,8 +1210,9 @@ autoLink = try $ do
12141210image :: GenParser Char ParserState Inline
12151211image = try $ do
12161212 char '!'
1217− (Link lab src) <- link
1218− return $ Image lab src
1213+ lab <- reference
1214+ (src, tit) <- source <|> referenceLink lab
1215+ return $ Image lab (src,tit)
12191216
12201217note :: GenParser Char ParserState Inline
12211218note = try $ do