mirror of
https://github.com/danog/telegram-entities.git
synced 2024-11-26 12:14:44 +01:00
Add support for <span class="tg-spoiler">
This commit is contained in:
parent
c8dbbe7101
commit
5202723d6d
@ -316,6 +316,9 @@ final class Entities
|
|||||||
'pre' => $node->hasAttribute('language')
|
'pre' => $node->hasAttribute('language')
|
||||||
? ['type' => 'pre', 'language' => $node->getAttribute('language')]
|
? ['type' => 'pre', 'language' => $node->getAttribute('language')]
|
||||||
: ['type' => 'pre'],
|
: ['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')],
|
'tg-emoji' => ['type' => 'custom_emoji', 'custom_emoji_id' => (int) $node->getAttribute('emoji-id')],
|
||||||
'emoji' => ['type' => 'custom_emoji', 'custom_emoji_id' => (int) $node->getAttribute('id')],
|
'emoji' => ['type' => 'custom_emoji', 'custom_emoji_id' => (int) $node->getAttribute('id')],
|
||||||
'a' => self::handleLink($node->getAttribute('href')),
|
'a' => self::handleLink($node->getAttribute('href')),
|
||||||
@ -384,7 +387,7 @@ final class Entities
|
|||||||
"email" => '<a href="mailto:'.EntityTools::htmlEscape(EntityTools::mbSubstr($this->message, $offset, $length)).'">',
|
"email" => '<a href="mailto:'.EntityTools::htmlEscape(EntityTools::mbSubstr($this->message, $offset, $length)).'">',
|
||||||
"phone" => '<a href="phone:'.EntityTools::htmlEscape(EntityTools::mbSubstr($this->message, $offset, $length)).'">',
|
"phone" => '<a href="phone:'.EntityTools::htmlEscape(EntityTools::mbSubstr($this->message, $offset, $length)).'">',
|
||||||
"mention" => '<a href="https://t.me/'.EntityTools::htmlEscape(EntityTools::mbSubstr($this->message, $offset+1, $length-1)).'">',
|
"mention" => '<a href="https://t.me/'.EntityTools::htmlEscape(EntityTools::mbSubstr($this->message, $offset+1, $length-1)).'">',
|
||||||
"spoiler" => $allowTelegramTags ? '<tg-spoiler>' : '',
|
"spoiler" => $allowTelegramTags ? '<tg-spoiler>' : '<span class="tg-spoiler">',
|
||||||
"custom_emoji" => $allowTelegramTags ? '<tg-emoji emoji-id="'.$entity['custom_emoji_id'].'">' : '',
|
"custom_emoji" => $allowTelegramTags ? '<tg-emoji emoji-id="'.$entity['custom_emoji_id'].'">' : '',
|
||||||
"text_mention" => $allowTelegramTags ? '<a href="tg://user?id='.$entity['user']['id'].'">' : '',
|
"text_mention" => $allowTelegramTags ? '<a href="tg://user?id='.$entity['user']['id'].'">' : '',
|
||||||
default => '',
|
default => '',
|
||||||
@ -400,7 +403,7 @@ final class Entities
|
|||||||
"strikethrough" => '</s>',
|
"strikethrough" => '</s>',
|
||||||
"underline" => '</u>',
|
"underline" => '</u>',
|
||||||
"block_quote" => '</blockquote>',
|
"block_quote" => '</blockquote>',
|
||||||
"spoiler" => $allowTelegramTags ? '</tg-spoiler>' : '',
|
"spoiler" => $allowTelegramTags ? '</tg-spoiler>' : '</span>',
|
||||||
"custom_emoji" => $allowTelegramTags ? "</tg-emoji>" : '',
|
"custom_emoji" => $allowTelegramTags ? "</tg-emoji>" : '',
|
||||||
"text_mention" => $allowTelegramTags ? '</a>' : '',
|
"text_mention" => $allowTelegramTags ? '</a>' : '',
|
||||||
default => '',
|
default => '',
|
||||||
|
@ -262,7 +262,7 @@ class EntitiesTest extends TestCase
|
|||||||
yield [
|
yield [
|
||||||
'test',
|
'test',
|
||||||
'<tg-spoiler>test</tg-spoiler>',
|
'<tg-spoiler>test</tg-spoiler>',
|
||||||
'test',
|
'<span class="tg-spoiler">test</span>',
|
||||||
[[
|
[[
|
||||||
'type' => 'spoiler',
|
'type' => 'spoiler',
|
||||||
'offset' => 0,
|
'offset' => 0,
|
||||||
@ -618,6 +618,19 @@ class EntitiesTest extends TestCase
|
|||||||
],
|
],
|
||||||
'<b>'"</b>',
|
'<b>'"</b>',
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'html',
|
||||||
|
'<span class="tg-spoiler">spoiler</span>',
|
||||||
|
'spoiler',
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'offset' => 0,
|
||||||
|
'length' => 7,
|
||||||
|
'type' => 'spoiler',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'<tg-spoiler>spoiler</tg-spoiler>',
|
||||||
|
],
|
||||||
[
|
[
|
||||||
'html',
|
'html',
|
||||||
'<a href="mention:101374607">mention1</a> <a href="tg://user?id=101374607">mention2</a>',
|
'<a href="mention:101374607">mention1</a> <a href="tg://user?id=101374607">mention2</a>',
|
||||||
|
Loading…
Reference in New Issue
Block a user