From ad53cef76dce8b5a7c0c8547e8b3134f20e2be29 Mon Sep 17 00:00:00 2001 From: Richard Berger Date: Thu, 6 Oct 2016 20:23:06 -0400 Subject: [PATCH] Fix issue with external links containing anchors --- lammpsdoc/txt2rst.py | 2 +- tests/test_txt2rst.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lammpsdoc/txt2rst.py b/lammpsdoc/txt2rst.py index 6949cb6..9fac2f0 100755 --- a/lammpsdoc/txt2rst.py +++ b/lammpsdoc/txt2rst.py @@ -104,7 +104,7 @@ class RSTMarkup(Markup): anchor_pos = href.find('#') - if anchor_pos >= 0: + if anchor_pos >= 0 and not href.startswith('http'): href = href[anchor_pos+1:] return ":ref:`%s <%s>`" % (content, href) diff --git a/tests/test_txt2rst.py b/tests/test_txt2rst.py index f74f8b7..9bdb5b2 100644 --- a/tests/test_txt2rst.py +++ b/tests/test_txt2rst.py @@ -424,6 +424,11 @@ class TestSpecialCommands(unittest.TestCase): "one \n\n" "a :ref:`link ` to above\n\n", s) + def test_external_anchor_link(self): + s = self.txt2rst.convert('some text "containing a\n' + 'link"_http://lammps.sandia.gov/movies.html#granregion with an anchor') + self.assertEqual('some text `containing a link `_ with an anchor\n\n', s) + def test_define_link_alias(self): s = self.txt2rst.convert("one :link(alias,value)\n" "\"test\"_alias\n")