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

commit45895b561f36afc0bdb2a04765f638e91a199635 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSun 13 Jan 2013, 23:00 (14 years ago) parentf191aa4
2 files changed+38−34
src/Text/Pandoc/Writers/RST.hs+10−6 tests/writer.rst+28−28
src/Text/Pandoc/Writers/RST.hs+10−6
@@ -367,12 +367,16 @@ inlineToRST (Link txt (src, tit)) = do
367367 linktext <- inlineListToRST $ normalizeSpaces txt
368368 if useReferenceLinks
369369 then do refs <- get >>= return . stLinks
370− let refs' = if (txt, (src, tit)) `elem` refs
371− then refs
372− else (txt, (src, tit)):refs
373− modify $ \st -> st { stLinks = refs' }
374− return $ "`" <> linktext <> "`_"
375− else return $ "`" <> linktext <> " <" <> text src <> ">`_"
370+ case lookup txt refs of
371+ Just (src',tit') ->
372+ if src == src' && tit == tit'
373+ then return $ "`" <> linktext <> "`_"
374+ else do -- duplicate label, use non-reference link
375+ return $ "`" <> linktext <> " <" <> text src <> ">`__"
376+ Nothing -> do
377+ modify $ \st -> st { stLinks = (txt,(src,tit)):refs }
378+ return $ "`" <> linktext <> "`_"
379+ else return $ "`" <> linktext <> " <" <> text src <> ">`__"
376380inlineToRST (Image alternate (source, tit)) = do
377381 label <- registerImage alternate (source,tit) Nothing
378382 return $ "|" <> label <> "|"
tests/writer.rst+28−28
@@ -18,8 +18,8 @@ markdown test suite.
1818Headers
1919=======
2020
21−Level 2 with an `embedded link </url>`_
22−---------------------------------------
21+Level 2 with an `embedded link </url>`__
22+----------------------------------------
2323
2424Level 3 with *emphasis*
2525~~~~~~~~~~~~~~~~~~~~~~~
@@ -549,7 +549,7 @@ This is *emphasized*, and so *is this*.
549549
550550This is **strong**, and so **is this**.
551551
552−An *`emphasized link </url>`_*.
552+An *`emphasized link </url>`__*.
553553
554554***This is strong and em.***
555555
@@ -584,7 +584,7 @@ Smart quotes, ellipses, dashes
584584‘He said, “I want to go.”’ Were you alive in the 70’s?
585585
586586Here is some quoted ‘``code``’ and a “`quoted
587−link <http://example.com/?foo=1&bar=2>`_”.
587+link <http://example.com/?foo=1&bar=2>`__”.
588588
589589Some dashes: one—two — three—four — five.
590590
@@ -690,42 +690,42 @@ Links
690690Explicit
691691--------
692692
693−Just a `URL </url/>`_.
693+Just a `URL </url/>`__.
694694
695−`URL and title </url/>`_.
695+`URL and title </url/>`__.
696696
697−`URL and title </url/>`_.
697+`URL and title </url/>`__.
698698
699−`URL and title </url/>`_.
699+`URL and title </url/>`__.
700700
701−`URL and title </url/>`_
701+`URL and title </url/>`__
702702
703−`URL and title </url/>`_
703+`URL and title </url/>`__
704704
705−`with\_underscore </url/with_underscore>`_
705+`with\_underscore </url/with_underscore>`__
706706
707−`Email link <mailto:nobody@nowhere.net>`_
707+`Email link <mailto:nobody@nowhere.net>`__
708708
709−`Empty <>`_.
709+`Empty <>`__.
710710
711711Reference
712712---------
713713
714−Foo `bar </url/>`_.
714+Foo `bar </url/>`__.
715715
716−Foo `bar </url/>`_.
716+Foo `bar </url/>`__.
717717
718−Foo `bar </url/>`_.
718+Foo `bar </url/>`__.
719719
720−With `embedded [brackets] </url/>`_.
720+With `embedded [brackets] </url/>`__.
721721
722−`b </url/>`_ by itself should be a link.
722+`b </url/>`__ by itself should be a link.
723723
724−Indented `once </url>`_.
724+Indented `once </url>`__.
725725
726−Indented `twice </url>`_.
726+Indented `twice </url>`__.
727727
728−Indented `thrice </url>`_.
728+Indented `thrice </url>`__.
729729
730730This should [not][] be a link.
731731
@@ -733,21 +733,21 @@ This should [not][] be a link.
733733
734734 [not]: /url
735735
736−Foo `bar </url/>`_.
736+Foo `bar </url/>`__.
737737
738−Foo `biz </url/>`_.
738+Foo `biz </url/>`__.
739739
740740With ampersands
741741---------------
742742
743743Here’s a `link with an ampersand in the
744−URL <http://example.com/?foo=1&bar=2>`_.
744+URL <http://example.com/?foo=1&bar=2>`__.
745745
746−Here’s a link with an amersand in the link text: `AT&T <http://att.com/>`_.
746+Here’s a link with an amersand in the link text: `AT&T <http://att.com/>`__.
747747
748−Here’s an `inline link </script?foo=1&bar=2>`_.
748+Here’s an `inline link </script?foo=1&bar=2>`__.
749749
750−Here’s an `inline link in pointy braces </script?foo=1&bar=2>`_.
750+Here’s an `inline link in pointy braces </script?foo=1&bar=2>`__.
751751
752752Autolinks
753753---------
@@ -815,7 +815,7 @@ This paragraph should not be part of the note, as it is not indented.
815815
816816.. [3]
817817 This is *easier* to type. Inline notes may contain
818− `links <http://google.com>`_ and ``]`` verbatim characters, as well as
818+ `links <http://google.com>`__ and ``]`` verbatim characters, as well as
819819 [bracketed text].
820820
821821.. [4]