Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow rendering emojis when not surrounded by spaces #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
phpunit.xml
vendor
.phpunit.result.cache
13 changes: 0 additions & 13 deletions src/EmojiParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ public function parse(InlineParserContext $inlineContext): bool
{
$cursor = $inlineContext->getCursor();

$previous = $cursor->peek(-1);
if ($previous !== null && $previous !== ' ') {
return false;
}

$saved = $cursor->saveState();

$cursor->advance();
Expand All @@ -92,14 +87,6 @@ public function parse(InlineParserContext $inlineContext): bool
return false;
}

$next = $cursor->peek(0);

if ($next !== null && $next !== ' ') {
$cursor->restoreState($saved);

return false;
}

$key = substr($handle, 0, -1);

if ($this->map === null) {
Expand Down
3 changes: 2 additions & 1 deletion tests/EmojiParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ public function provideRenderCases()
[':+1:', '<p><img class="emoji" data-emoji="+1" src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f44d.png?v5" alt="+1" /></p>'],
['* :airplane:', "<ul>\n<li>\n<img class=\"emoji\" data-emoji=\"airplane\" src=\"https://assets-cdn.github.com/images/icons/emoji/unicode/2708.png?v5\" alt=\"airplane\" />\n</li>\n</ul>"],
['foo bar baz: lol', '<p>foo bar baz: lol</p>'],
[':+1:123', '<p>:+1:123</p>'],
[':+1:123', '<p><img class="emoji" data-emoji="+1" src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f44d.png?v5" alt="+1" />123</p>'],
[':123123123:', '<p>:123123123:</p>'],
[':+1 :', '<p>:+1 :</p>'],
[':+1::+1:', '<p><img class="emoji" data-emoji="+1" src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f44d.png?v5" alt="+1" /><img class="emoji" data-emoji="+1" src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f44d.png?v5" alt="+1" /></p>'],
[':8ball: :100:', '<p><img class="emoji" data-emoji="8ball" src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f3b1.png?v5" alt="8ball" /> <img class="emoji" data-emoji="100" src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f4af.png?v5" alt="100" /></p>'],
];
}
Expand Down