diff --git a/src/Entities.php b/src/Entities.php index 8d3f0d7..f943b3f 100644 --- a/src/Entities.php +++ b/src/Entities.php @@ -316,6 +316,9 @@ private static function parseNode(DOMNode|DOMText $node, int $offset, string &$m 'pre' => $node->hasAttribute('language') ? ['type' => 'pre', 'language' => $node->getAttribute('language')] : ['type' => 'pre'], + 'span' => $node->hasAttribute('class') && $node->getAttribute('class') === 'tg-spoiler' + ? ['type' => 'spoiler'] + : null, 'tg-emoji' => ['type' => 'custom_emoji', 'custom_emoji_id' => (int) $node->getAttribute('emoji-id')], 'emoji' => ['type' => 'custom_emoji', 'custom_emoji_id' => (int) $node->getAttribute('id')], 'a' => self::handleLink($node->getAttribute('href')), @@ -384,7 +387,7 @@ public function toHTML(bool $allowTelegramTags = false): string "email" => '', "phone" => '', "mention" => '', - "spoiler" => $allowTelegramTags ? '' : '', + "spoiler" => $allowTelegramTags ? '' : '', "custom_emoji" => $allowTelegramTags ? '' : '', "text_mention" => $allowTelegramTags ? '' : '', default => '', @@ -400,7 +403,7 @@ public function toHTML(bool $allowTelegramTags = false): string "strikethrough" => '', "underline" => '', "block_quote" => '', - "spoiler" => $allowTelegramTags ? '' : '', + "spoiler" => $allowTelegramTags ? '' : '', "custom_emoji" => $allowTelegramTags ? "" : '', "text_mention" => $allowTelegramTags ? '' : '', default => '', diff --git a/tests/EntitiesTest.php b/tests/EntitiesTest.php index 6922d62..1ba6213 100644 --- a/tests/EntitiesTest.php +++ b/tests/EntitiesTest.php @@ -262,7 +262,7 @@ public static function provideHtmlEntities(): iterable yield [ 'test', 'test', - 'test', + 'test', [[ 'type' => 'spoiler', 'offset' => 0, @@ -618,6 +618,19 @@ private function provideEntities(): array ], ''"', ], + [ + 'html', + 'spoiler', + 'spoiler', + [ + [ + 'offset' => 0, + 'length' => 7, + 'type' => 'spoiler', + ], + ], + 'spoiler', + ], [ 'html', 'mention1 mention2',