diff --git a/src/Html2Text.php b/src/Html2Text.php index 5ba429e..5001b2f 100644 --- a/src/Html2Text.php +++ b/src/Html2Text.php @@ -434,10 +434,16 @@ protected function buildlinkList($link, $display, $linkOverride = null) return $display . ' [' . ($index + 1) . ']'; } elseif ($linkMethod == 'nextline') { + if ($url === $display) { + return $display; + } return $display . "\n[" . $url . ']'; } elseif ($linkMethod == 'bbcode') { return sprintf('[url=%s]%s[/url]', $url, $display); } else { // link_method defaults to inline + if ($url === $display) { + return $display; + } return $display . ' [' . $url . ']'; } } diff --git a/test/LinkTest.php b/test/LinkTest.php index 84aa072..626fd87 100644 --- a/test/LinkTest.php +++ b/test/LinkTest.php @@ -145,4 +145,18 @@ public function testDoLinksBBCode() $this->assertEquals($expected, $html2text->getText()); } + + public function testDoLinksWhenTargetInText() + { + $html = 'http://example.com'; + $expected = 'http://example.com'; + + $html2text = new Html2Text($html, array('do_links' => 'inline')); + + $this->assertEquals($expected, $html2text->getText()); + + $html2text = new Html2Text($html, array('do_links' => 'nextline')); + + $this->assertEquals($expected, $html2text->getText()); + } }