1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-10 16:08:24 +01:00

Add getHTML method

This commit is contained in:
Mahdi 2024-12-02 20:38:24 +03:30
parent 032c4fe80a
commit 15e21eeba8

View File

@ -17,6 +17,7 @@
namespace danog\MadelineProto\EventHandler\Message\Entities;
use danog\MadelineProto\ParseMode;
use danog\MadelineProto\StrTools;
use JsonSerializable;
final class TextWithEntities implements JsonSerializable
@ -42,4 +43,25 @@ final class TextWithEntities implements JsonSerializable
}
return $res;
}
protected readonly string $html;
protected readonly string $htmlTelegram;
/**
* Get an HTML version of the message.
*
* @psalm-suppress InaccessibleProperty
*
* @param bool $allowTelegramTags Whether to allow telegram-specific tags like tg-spoiler, tg-emoji, mention links and so on...
*/
public function getHTML(bool $allowTelegramTags = false): string
{
if (!$this->entities) {
return StrTools::htmlEscape($this->text);
}
if ($allowTelegramTags) {
return $this->htmlTelegram ??= StrTools::entitiesToHtml($this->text, MessageEntity::fromRawEntities($this->entities), $allowTelegramTags);
}
return $this->html ??= StrTools::entitiesToHtml($this->text, MessageEntity::fromRawEntities($this->entities), $allowTelegramTags);
}
}