phpbotgram

TextDecoration
in package

AbstractYes

Abstract base for text decoration strategies (HTML, Markdown V2).

Port of upstream aiogram/utils/text_decorations.pyTextDecoration.

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
string

quote()

Escape plain text for safe embedding in the target markup format.

public abstract quote(string $value) : string
Parameters
$value : string
Return values
string

unparse()

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
string

blockquote()

protected abstract blockquote(string $value) : string
Parameters
$value : string
Return values
string

bold()

protected abstract bold(string $value) : string
Parameters
$value : string
Return values
string

code()

protected abstract code(string $value) : string
Parameters
$value : string
Return values
string

customEmoji()

protected abstract customEmoji(string $value, string $customEmojiId) : string
Parameters
$value : string
$customEmojiId : string
Return values
string

dateTime()

protected abstract dateTime(string $value, int $unixTime, string|null $dateTimeFormat) : string
Parameters
$value : string
$unixTime : int
$dateTimeFormat : string|null
Return values
string

expandableBlockquote()

protected abstract expandableBlockquote(string $value) : string
Parameters
$value : string
Return values
string

italic()

protected abstract italic(string $value) : string
Parameters
$value : string
Return values
string
protected abstract link(string $value, string $link) : string
Parameters
$value : string
$link : string
Return values
string

pre()

protected abstract pre(string $value) : string
Parameters
$value : string
Return values
string

preLanguage()

protected abstract preLanguage(string $value, string $language) : string
Parameters
$value : string
$language : string
Return values
string

spoiler()

protected abstract spoiler(string $value) : string
Parameters
$value : string
Return values
string

strikethrough()

protected abstract strikethrough(string $value) : string
Parameters
$value : string
Return values
string

underline()

protected abstract underline(string $value) : string
Parameters
$value : string
Return values
string

addSurrogates()

Convert a UTF-8 string to a UTF-16LE byte string (add surrogates).

private static addSurrogates(string $text) : string
Parameters
$text : string
Return values
string

removeSurrogates()

Convert a UTF-16LE byte string back to UTF-8 (remove surrogates).

private static removeSurrogates(string $bytes) : string
Parameters
$bytes : string
Return values
string

unparseEntities()

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
Return values
Generator<mixed, void>
On this page

Search results