public function handleCommentContent(BaseComment $comment) { $content = $this->escape($comment->getCommentBody()); $replacements = []; $users = []; $mentions = Tags::parseMentionTags($content); foreach ($mentions as $username) { $tag = '@' . $username; if (!isset($replacements[$tag])) { $user = $this->userRepo->findOneByUsername($username); if ($user) { $users[$username] = $user; $replacements[$tag] = "<a data-user-id=\"{$user->getId()}\">{$tag}</a>"; } } } $content = UrlConverter::wrapLinks($content); $content = Tags::replaceMentionTags($content, $replacements); $content = Tags::wrapHashTags($content); $comment->setCommentBodyHtml($content); return $users; }
/** * @group parser */ public function testWrapHashTags() { $this->assertEquals('<a data-hashtag="#powerline">#powerline</a>', Tags::wrapHashTags('#powerline')); $this->assertEquals('<a data-hashtag="#powerline">#powerline</a> <a data-hashtag="#politics">#politics</a>', Tags::wrapHashTags('#powerline #politics')); $this->assertEquals('<a data-hashtag="#powerline">#powerline</a>.', Tags::wrapHashTags('#powerline.')); }