diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-01-13 23:00:05 -0800 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-01-13 23:00:05 -0800 |
commit | 45895b561f36afc0bdb2a04765f638e91a199635 (patch) | |
tree | 275f63d991c399ad1f90f767542ea1bd2daa6136 /src/Text/Pandoc | |
parent | f191aa4a986d2f60a73df28d343c9848a5c38c64 (diff) | |
download | pandoc-45895b561f36afc0bdb2a04765f638e91a199635.tar.gz |
RST writer: Fixes bug with links with duplicate text.
We now (a) use anonymous links for links with inline URLs, and
(b) use an inline link instead of a reference link if the
reference link would require a label that has already been
used for a different link.
Closes #511.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Writers/RST.hs | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Writers/RST.hs b/src/Text/Pandoc/Writers/RST.hs index 2ec2ef127..f3815011f 100644 --- a/src/Text/Pandoc/Writers/RST.hs +++ b/src/Text/Pandoc/Writers/RST.hs @@ -367,12 +367,16 @@ inlineToRST (Link txt (src, tit)) = do linktext <- inlineListToRST $ normalizeSpaces txt if useReferenceLinks then do refs <- get >>= return . stLinks - let refs' = if (txt, (src, tit)) `elem` refs - then refs - else (txt, (src, tit)):refs - modify $ \st -> st { stLinks = refs' } - return $ "`" <> linktext <> "`_" - else return $ "`" <> linktext <> " <" <> text src <> ">`_" + case lookup txt refs of + Just (src',tit') -> + if src == src' && tit == tit' + then return $ "`" <> linktext <> "`_" + else do -- duplicate label, use non-reference link + return $ "`" <> linktext <> " <" <> text src <> ">`__" + Nothing -> do + modify $ \st -> st { stLinks = (txt,(src,tit)):refs } + return $ "`" <> linktext <> "`_" + else return $ "`" <> linktext <> " <" <> text src <> ">`__" inlineToRST (Image alternate (source, tit)) = do label <- registerImage alternate (source,tit) Nothing return $ "|" <> label <> "|" |