Formatting API¶
aiogram-style composable formatting built on Peyk’s RichText IR.
The composition objects are platform-neutral. Rendering happens only when a target platform is known, so application code does not carry platform names.
- class peyk.formatting.Text(*body: str | RichText | Text, sep: str = '')[source]¶
Bases:
objectA composable sequence of text fragments and formatting nodes.
- bold(*body: str | RichText | Text) Text[source]¶
Append a bold fragment and return a new composition.
- italic(*body: str | RichText | Text) Text[source]¶
Append an italic fragment and return a new composition.
- underline(*body: str | RichText | Text) Text[source]¶
Append an underlined fragment and return a new composition.
- strikethrough(*body: str | RichText | Text) Text[source]¶
Append a strikethrough fragment and return a new composition.
- spoiler(*body: str | RichText | Text) Text[source]¶
Append a spoiler fragment and return a new composition.
- code(*body: str | RichText | Text) Text[source]¶
Append an inline-code fragment and return a new composition.
- pre(*body: str | RichText | Text, language: str | None = None) Text[source]¶
Append a preformatted fragment and return a new composition.
- link(text: str | RichText | Text, url: str) Text[source]¶
Append a URL link and return a new composition.
- mention(text: str | RichText | Text, user_id: int | str) Text[source]¶
Append a Telegram user mention and return a new composition.
- blockquote(*body: str | RichText | Text) Text[source]¶
Append a block quote and return a new composition.
- expandable_blockquote(*body: str | RichText | Text) Text[source]¶
Append an expandable block quote and return a new composition.
- render(target: PlatformCapabilities | str) str[source]¶
Render this composition for a platform or audited capability object.
- as_kwargs(target: PlatformCapabilities | str) dict[str, object][source]¶
Return the exact text-bearing keyword arguments for
target.
- class peyk.formatting.Bold(*body: str | RichText | Text, sep: str = '')[source]¶
Bases:
TextRender children in bold.
- class peyk.formatting.Italic(*body: str | RichText | Text, sep: str = '')[source]¶
Bases:
TextRender children in italics.
- class peyk.formatting.Underline(*body: str | RichText | Text, sep: str = '')[source]¶
Bases:
TextRender children with an underline where the target supports it.
- class peyk.formatting.Strikethrough(*body: str | RichText | Text, sep: str = '')[source]¶
Bases:
TextRender children with a strikethrough where the target supports it.
- class peyk.formatting.Spoiler(*body: str | RichText | Text, sep: str = '')[source]¶
Bases:
TextRender children as a spoiler where the target supports it.
- class peyk.formatting.Code(*body: str | RichText | Text, sep: str = '')[source]¶
Bases:
TextRender children as inline code.
- class peyk.formatting.Pre(*body: str | RichText | Text, language: str | None = None)[source]¶
Bases:
TextRender children as a preformatted block.
- language: str | None¶
- class peyk.formatting.TextLink(*body: str | RichText | Text, url: str)[source]¶
Bases:
TextRender children as a URL link.
- url: str¶
- class peyk.formatting.TextMention(*body: str | RichText | Text, user_id: int | str)[source]¶
Bases:
TextRender children as a Telegram user mention.
- user_id: int | str¶
- class peyk.formatting.BlockQuote(*body: str | RichText | Text, sep: str = '')[source]¶
Bases:
TextRender children as a block quote.
- class peyk.formatting.ExpandableBlockQuote(*body: str | RichText | Text, sep: str = '')[source]¶
Bases:
TextRender children as an expandable block quote.
- peyk.formatting.as_line(*items: str | RichText | Text, sep: str = ' ') Text[source]¶
Join items on one line.
- peyk.formatting.as_list(*items: str | RichText | Text | Iterable[str | RichText | Text], sep: str = '\n') Text[source]¶
Join items as a list separated by
sep; one iterable is also accepted.
- peyk.formatting.as_marked_list(*items: str | ~peyk.utils.text_formatting.RichText | ~peyk.formatting.Text | ~typing.Iterable[str | ~peyk.utils.text_formatting.RichText | ~peyk.formatting.Text], marker: str = '▫️', se, sep: str = ) ->) Text[source]¶
Prefix each item with
marker.
- peyk.formatting.as_numbered_list(*items: str | RichText | Text | Iterable[str | RichText | Text], sep: str = '\n') Text[source]¶
Prefix each item with its one-based position.
- peyk.formatting.as_section(title: str | RichText | Text, *body: str | RichText | Text, sep: str = '\n') Text[source]¶
Return a title followed by body lines.
- peyk.formatting.as_marked_section(title: str | ~peyk.utils.text_formatting.RichText | ~peyk.formatting.Text, *body: str | ~peyk.utils.text_formatting.RichText | ~peyk.formatting.Text, marker: str = '▫️', se, sep: str = ) ->) Text[source]¶
Return a title followed by a marked list.
- peyk.formatting.as_key_value(key: str | RichText | Text, value: str | RichText | Text, sep: str = ': ') Text[source]¶
Join a key and value with
sep.
- peyk.formatting.resolve_text(content: str | RichText | Text, platform_caps: PlatformCapabilities, policy: UnsupportedPolicy, defaults: TextDefaults) tuple[str, dict[str, object]][source]¶
Resolve text once at send time into target text and native keyword arguments.
Plain strings remain plain unless a default parse mode is configured. Rich compositions are rendered from the neutral IR; Rubika additionally receives its structured metadata. Explicit parse-mode handling is applied by
peyk.Botbefore this resolver is called.
- class peyk.formatting.TextDefaults(*args, **kwargs)[source]¶
Bases:
ProtocolMinimal defaults contract required by
resolve_text().
- peyk.formatting.bold(text: str | RichText) RichText[source]¶
Performs the bold operation for the utility client.
- Parameters:
text – Text content supplied to the operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.italic(text: str | RichText) RichText[source]¶
Performs the italic operation for the utility client.
- Parameters:
text – Text content supplied to the operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.underline(text: str | RichText) RichText[source]¶
Performs the underline operation for the utility client.
- Parameters:
text – Text content supplied to the operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.strikethrough(text: str | RichText) RichText[source]¶
Performs the strikethrough operation for the utility client.
- Parameters:
text – Text content supplied to the operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.spoiler(text: str | RichText) RichText[source]¶
Performs the spoiler operation for the utility client.
- Parameters:
text – Text content supplied to the operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.code(text: str | RichText) RichText[source]¶
Performs the code operation for the utility client.
- Parameters:
text – Text content supplied to the operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.pre(text: str | RichText, language: str | None = None) RichText[source]¶
Performs the pre operation for the utility client.
- Parameters:
text – Text content supplied to the operation.
language – Value used by this operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.link(text: str | RichText, url: str) RichText[source]¶
Performs the link operation for the utility client.
- Parameters:
text – Text content supplied to the operation.
url – Target URL.
- Returns:
Result produced by the utility operation.
- peyk.formatting.mention_user(text: str | RichText, user_id: int | str) RichText[source]¶
Performs the mention user operation for the utility client.
- Parameters:
text – Text content supplied to the operation.
user_id – Identifier of the target user.
- Returns:
Result produced by the utility operation.
- peyk.formatting.mention_username(text: str | RichText, username: str) RichText[source]¶
Performs the mention username operation for the utility client.
- Parameters:
text – Text content supplied to the operation.
username – Value used by this operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.bale_expandable(title: str, text: str | RichText) RichText[source]¶
Performs the bale expandable operation for the utility client.
- Parameters:
title – Title to apply to the target resource.
text – Text content supplied to the operation.
- Returns:
Result produced by the utility operation.