mirror of
https://github.com/danog/MadelineProto.git
synced 2025-01-10 13:28:16 +01:00
Add getHTML method
This commit is contained in:
parent
032c4fe80a
commit
15e21eeba8
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user