git.iko.soy/typeable/pandoc
on master help sign in
Fixed RST links with no explicit link text.

The link `<foo>`_ should have `foo` as both its link text and its URL. See RST spec at <http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#embedded-uris-and-aliases> "The reference text may also be omitted, in which case the URI will be duplicated for use as the reference text. This is useful for relative URIs where the address or file name is also the desired reference text: See `<a_named_relative_link>`_ or `<an_anonymous_relative_link>`__ for details." Closes Debian #828167 -- reported by Christian Heller.

commitd283f9c864fc4a9ed8ffa4711dda9014b886149b authorJohn MacFarlane <jgm@berkeley.edu> dateSat 25 Jun 2016, 10:56 (10 years ago) parenta429480
3 files changed+7−1
src/Text/Pandoc/Readers/RST.hs+4−1 tests/rst-reader.native+1 tests/rst-reader.rst+2
src/Text/Pandoc/Readers/RST.hs+4−1
@@ -1126,7 +1126,10 @@ explicitLink = try $ do
11261126 skipSpaces
11271127 string "`_"
11281128 optional $ char '_' -- anonymous form
1129− return $ B.link (escapeURI $ trim src) "" label'
1129+ let label'' = if label' == mempty
1130+ then B.str src
1131+ else label'
1132+ return $ B.link (escapeURI $ trim src) "" label''
11301133
11311134referenceLink :: RSTParser Inlines
11321135referenceLink = try $ do
tests/rst-reader.native+1
@@ -211,6 +211,7 @@ Pandoc (Meta {unMeta = fromList [("author",MetaList [MetaInlines [Str "John",Spa
211211,Para [Str "Minus:",Space,Str "-"]
212212,Header 1 ("links",[],[]) [Str "Links"]
213213,Para [Str "Explicit:",Space,Str "a",Space,Link ("",[],[]) [Str "URL"] ("/url/",""),Str "."]
214+,Para [Str "Explicit",Space,Str "with",Space,Str "no",Space,Str "label:",Space,Link ("",[],[]) [Str "foo"] ("foo",""),Str "."]
214215,Para [Str "Two",Space,Str "anonymous",Space,Str "links:",Space,Link ("",[],[]) [Str "the",Space,Str "first"] ("/url1/",""),Space,Str "and",Space,Link ("",[],[]) [Str "the",Space,Str "second"] ("/url2/","")]
215216,Para [Str "Reference",Space,Str "links:",Space,Link ("",[],[]) [Str "link1"] ("/url1/",""),Space,Str "and",Space,Link ("",[],[]) [Str "link2"] ("/url2/",""),Space,Str "and",Space,Link ("",[],[]) [Str "link1"] ("/url1/",""),Space,Str "again."]
216217,Para [Str "Here\8217s",Space,Str "a",Space,Link ("",[],[]) [Str "link",Space,Str "with",Space,Str "an",Space,Str "ampersand",Space,Str "in",Space,Str "the",Space,Str "URL"] ("http://example.com/?foo=1&bar=2",""),Str "."]
tests/rst-reader.rst+2
@@ -378,6 +378,8 @@ Links
378378
379379Explicit: a `URL </url/>`_.
380380
381+Explicit with no label: `<foo>`_.
382+
381383Two anonymous links: `the first`__ and `the second`__
382384
383385__ /url1/