MarkdownDecoration
extends TextDecoration
in package
Markdown V2 decoration strategy.
Port of upstream aiogram/utils/text_decorations.py — MarkdownDecoration.
Plain text is escaped via quote() which escapes all Markdown V2 special
characters: _*[]()~ >#+-=|}.!`
Each entity type applies the corresponding Markdown V2 syntax.
Table of Contents
Constants
- SPECIAL_CHARS : array<string|int, mixed> = [ '\\', // MUST BE FIRST — see backslash-doubli...
- All characters that must be escaped in Markdown V2 plain text.
Properties
- $instance : self|null
Methods
- applyEntity() : string
- Apply the decoration corresponding to a single MessageEntity to $text.
- instance() : self
- 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
Constants
SPECIAL_CHARS
All characters that must be escaped in Markdown V2 plain text.
private
array<string|int, mixed>
SPECIAL_CHARS
= [
'\\',
// MUST BE FIRST — see backslash-doubling note above.
'_',
'*',
'[',
']',
'(',
')',
'~',
'`',
'>',
'#',
'+',
'-',
'=',
'|',
'{',
'}',
'.',
'!',
]
Backslash MUST be listed first so that str_replace processes it before
any other character. If backslash came later it would double-escape the
backslashes that earlier replacements already inserted (e.g. _ → \_,
then \ → \\ would wrongly turn \_ into \\_).
Properties
$instance
private
static self|null
$instance
= null
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
stringinstance()
public
static instance() : self
Return values
selfquote()
Escape plain text for safe embedding in the target markup format.
public
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
blockquote(string $value) : string
Parameters
- $value : string
Return values
stringbold()
protected
bold(string $value) : string
Parameters
- $value : string
Return values
stringcode()
protected
code(string $value) : string
Parameters
- $value : string
Return values
stringcustomEmoji()
protected
customEmoji(string $value, string $customEmojiId) : string
Parameters
- $value : string
- $customEmojiId : string
Return values
stringdateTime()
protected
dateTime(string $value, int $unixTime, string|null $dateTimeFormat) : string
Parameters
- $value : string
- $unixTime : int
- $dateTimeFormat : string|null
Return values
stringexpandableBlockquote()
protected
expandableBlockquote(string $value) : string
Parameters
- $value : string
Return values
stringitalic()
protected
italic(string $value) : string
Parameters
- $value : string
Return values
stringlink()
protected
link(string $value, string $link) : string
Parameters
- $value : string
- $link : string
Return values
stringpre()
protected
pre(string $value) : string
Parameters
- $value : string
Return values
stringpreLanguage()
protected
preLanguage(string $value, string $language) : string
Parameters
- $value : string
- $language : string
Return values
stringspoiler()
protected
spoiler(string $value) : string
Parameters
- $value : string
Return values
stringstrikethrough()
protected
strikethrough(string $value) : string
Parameters
- $value : string
Return values
stringunderline()
protected
underline(string $value) : string
Parameters
- $value : string