Skip to content

Commit

Permalink
Merge pull request #157 from Sylry/preserve_spaces_in_link_anchor
Browse files Browse the repository at this point in the history
Preserve spaces in link anchor.
  • Loading branch information
colinodell authored May 19, 2018
2 parents 5fdd7d4 + ef839a7 commit e25879d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Converter/LinkConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function convert(ElementInterface $element)
{
$href = $element->getAttribute('href');
$title = $element->getAttribute('title');
$text = trim($element->getValue());
$text = trim($element->getValue(), "\t\n\r\0\x0B");

if ($title !== '') {
$markdown = '[' . $text . '](' . $href . ' "' . $title . '")';
Expand Down
2 changes: 2 additions & 0 deletions tests/HtmlConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public function test_anchor()
$this->html_gives_markdown('<a href="http://modernnerd.net">http://modernnerd.net</a>', '<http://modernnerd.net>');
$this->html_gives_markdown('<a href="http://modernnerd.net" title="Title">Modern Nerd</a>', '[Modern Nerd](http://modernnerd.net "Title")');
$this->html_gives_markdown('<a href="http://modernnerd.net" title="Title">Modern Nerd</a> <a href="http://modernnerd.net" title="Title">Modern Nerd</a>', '[Modern Nerd](http://modernnerd.net "Title") [Modern Nerd](http://modernnerd.net "Title")');
$this->html_gives_markdown('<a href="http://modernnerd.net"><h3>Modern Nerd</h3></a>', '[### Modern Nerd](http://modernnerd.net)');
$this->html_gives_markdown('The <a href="http://modernnerd.net">Modern Nerd </a>(MN)', 'The [Modern Nerd ](http://modernnerd.net)(MN)');
$this->html_gives_markdown('<a href="http://modernnerd.net/" title="Title"><img src="/path/img.jpg" alt="alt text" title="Title"/></a>', '[![alt text](/path/img.jpg "Title")](http://modernnerd.net/ "Title")');
$this->html_gives_markdown('<a href="http://modernnerd.net/" title="Title"><img src="/path/img.jpg" alt="alt text" title="Title"/> Test</a>', '[![alt text](/path/img.jpg "Title") Test](http://modernnerd.net/ "Title")');

Expand Down

0 comments on commit e25879d

Please sign in to comment.