TextDecoration
in package
Abstract base for text decoration strategies (HTML, Markdown V2).
Port of upstream aiogram/utils/text_decorations.py — TextDecoration.
Telegram entity offsets/lengths are expressed in UTF-16 code units. PHP strings are byte sequences, so we convert the input to a UTF-16LE byte string and multiply all offsets/lengths by 2 to get byte offsets. After slicing we convert back to UTF-8.
Table of Contents
Methods
- applyEntity() : string
- Apply the decoration corresponding to a single MessageEntity to $text.
- quote() : string
- Escape plain text for safe embedding in the target markup format.
- unparse() : string
- Reconstruct a decorated string from $text and its entity list.
- blockquote() : string
- bold() : string
- code() : string
- customEmoji() : string
- dateTime() : string
- expandableBlockquote() : string
- italic() : string
- link() : string
- pre() : string
- preLanguage() : string
- spoiler() : string
- strikethrough() : string
- underline() : string
- addSurrogates() : string
- Convert a UTF-8 string to a UTF-16LE byte string (add surrogates).
- removeSurrogates() : string
- Convert a UTF-16LE byte string back to UTF-8 (remove surrogates).
- unparseEntities() : Generator<mixed, void>
- Recursively walk entities within [$offset, $offset+$length) and yield decorated text segments.
Methods
applyEntity()
Apply the decoration corresponding to a single MessageEntity to $text.
public
final applyEntity(MessageEntity $entity, string $text) : string
$text is already the inner (possibly recursively-decorated) substring.
Parameters
- $entity : MessageEntity
- $text : string
Return values
stringquote()
Escape plain text for safe embedding in the target markup format.
public
abstract quote(string $value) : string
Parameters
- $value : string
Return values
stringunparse()
Reconstruct a decorated string from $text and its entity list.
public
final unparse(string $text[, null|array<int, MessageEntity> $entities = null ]) : string
Mirrors upstream TextDecoration.unparse().
Parameters
- $text : string
- $entities : null|array<int, MessageEntity> = null
Return values
stringblockquote()
protected
abstract blockquote(string $value) : string
Parameters
- $value : string
Return values
stringbold()
protected
abstract bold(string $value) : string
Parameters
- $value : string
Return values
stringcode()
protected
abstract code(string $value) : string
Parameters
- $value : string
Return values
stringcustomEmoji()
protected
abstract customEmoji(string $value, string $customEmojiId) : string
Parameters
- $value : string
- $customEmojiId : string
Return values
stringdateTime()
protected
abstract dateTime(string $value, int $unixTime, string|null $dateTimeFormat) : string
Parameters
- $value : string
- $unixTime : int
- $dateTimeFormat : string|null
Return values
stringexpandableBlockquote()
protected
abstract expandableBlockquote(string $value) : string
Parameters
- $value : string
Return values
stringitalic()
protected
abstract italic(string $value) : string
Parameters
- $value : string
Return values
stringlink()
protected
abstract link(string $value, string $link) : string
Parameters
- $value : string
- $link : string
Return values
stringpre()
protected
abstract pre(string $value) : string
Parameters
- $value : string
Return values
stringpreLanguage()
protected
abstract preLanguage(string $value, string $language) : string
Parameters
- $value : string
- $language : string
Return values
stringspoiler()
protected
abstract spoiler(string $value) : string
Parameters
- $value : string
Return values
stringstrikethrough()
protected
abstract strikethrough(string $value) : string
Parameters
- $value : string
Return values
stringunderline()
protected
abstract underline(string $value) : string
Parameters
- $value : string
Return values
stringaddSurrogates()
Convert a UTF-8 string to a UTF-16LE byte string (add surrogates).
private
static addSurrogates(string $text) : string
Parameters
- $text : string
Return values
stringremoveSurrogates()
Convert a UTF-16LE byte string back to UTF-8 (remove surrogates).
private
static removeSurrogates(string $bytes) : string
Parameters
- $bytes : string
Return values
stringunparseEntities()
Recursively walk entities within [$offset, $offset+$length) and yield decorated text segments.
private
unparseEntities(string $utf16Bytes, array<int, MessageEntity> $entities, int $offset, int $length) : Generator<mixed, void>
Parameters
- $utf16Bytes : string
- $entities : array<int, MessageEntity>
- $offset : int
- $length : int