Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/CommonMark/Extensions/Link/LinkRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ private function isInternalLink(string $url): bool
return true;
}

// Emails
if (str_starts_with($url, 'mailto:')) {
return true;
}

return false;
}
}
33 changes: 20 additions & 13 deletions tests/CommonMark/Extensions/Link/LinkRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,31 @@
$environment = new Environment();
$environment->addRenderer(Text::class, new TextRenderer());

assertMatchesSnapshot((string) $subject->render(new Link($url, 'Label', 'Title'), new HtmlRenderer($environment)));
$element = $subject->render(new Link($url, 'Label', 'Title'), new HtmlRenderer($environment));

$this->expect($element->getAttribute('target'))->not->toBe('_blank');
assertMatchesSnapshot((string) $element);
})->with([
'https://ourapp.com',
'#heading',
'/path/segment',
'mailto:test@ark.io',
]);

// it('should render external links', function (string $url) {
// $subject = new LinkRenderer();
// $subject->setConfiguration(new Configuration());
it('should render external links', function (string $url) {
$subject = new LinkRenderer();
$subject->setConfiguration(new Configuration());

$environment = new Environment();
$environment->addRenderer(Text::class, new TextRenderer());

// $environment = new Environment();
// $environment->addRenderer(Text::class, new TextRenderer());
$element = $subject->render(new Link($url, 'Label', 'Title'), new HtmlRenderer($environment));

// assertMatchesSnapshot((string) $subject->render(new Link($url, 'Label', 'Title'), new HtmlRenderer($environment)));
// })->with([
// 'https://google.com',
// 'unsupported/relative/url', // is valid, but currently not supported
// 'ftp://google.com',
// '//google.com',
// ]);
$this->expect($element->getAttribute('target'))->toBe('_blank');
assertMatchesSnapshot((string) $element);
})->with([
'https://google.com',
'unsupported/relative/url', // is valid, but currently not supported
'ftp://google.com',
'//google.com',
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a href="mailto:test@ark.io" title="Title">Label</a>