Skip to main content
Version: 2.2.2-1

Formatting

RimTUB uses HTML markup for formatting messages.

warning

It is strongly recommended to use the formatting functions (described here) for text formatting.

Why?

  • Security: When using formatting functions, all input text is escaped, preventing formatting errors.
  • Compatibility: If formatting in Pyrogram is updated (e.g., tag or attribute names change), you won't need to rewrite all formatting.

Quick Summary of Formatting Functions

FunctionDescriptionExample
escape("<text & <<>")Escapes text for substitution. Built into all formatting functions.&lt;text &amp; &lt;&lt;&gt;
code('text')Monospaced text. Can be copied with a click.text
pre('code', "py")Code block with syntax highlighting.
code
emoji(5404799425245626483, "🌟")Premium emoji. The ID can be retrieved using the .emjs command.🌟
bq("text", True)Blockquote. If the second argument is True, the quote can be collapsed/expanded.
text
blockquote("text", True)Same as bq.
text
b('text')Bold text.text
i('text')Italic text.text
s('text')Strikethrough text.text
u('text')Underlined text.text
a('text', 'https://t.me/RimTUB')Hyperlink.text
spoiler('text')Spoiler. Text will only be revealed upon clicking.not displayable

All Functions

escape

Escapes special HTML characters in a string.

Arguments:

  • text (str): Text to escape.

Returns: str - Escaped text.

Example:

escape("<notag>Test & Test</notag>")

format_tag

Generates an HTML tag.

Arguments:

  • tag_name (str): Tag name, e.g., "a" or "div".
  • content (str) = "": Tag content.
  • escape_content (bool) = True: Whether to escape the content.
  • close_tag (bool) = True: Whether a closing tag is needed.
  • kwargs (dict): Tag attributes.

Returns: str - Generated HTML tag.

Example:

format_tag('new_formatting_on_TG', 'test text', color="Red")

code

Creates an HTML tag for code.

Arguments:

  • text (str): Code to place inside the tag.
  • escape_html (bool) = True: Whether to escape HTML in the code.

Returns: str - Generated HTML tag for code.

Example:

code('print("Hello World")')

pre

Generates an HTML tag for displaying a code block.

Arguments:

  • text (str): Code to display inside the tag.
  • lang (str) = "": Programming language.
  • escape_html (bool) = True: Whether to escape HTML.

Returns: str - Generated HTML tag for displaying a code block.

Example:

pre('print("Hello World")', lang="python")

blockquote

Creates an HTML tag for a blockquote.

Arguments:

  • text (str): Text to place inside the tag.
  • expandable (bool) = False: Whether the quote can be expanded.
  • escape_html (bool) = True: Whether to escape HTML.

Returns: str - Generated HTML tag for a blockquote.

Example:

blockquote('This is a quote.', expandable=True)

bq

Same as blockquote. Creates an HTML tag for a blockquote.

Arguments:

  • text (str): Text to place inside the tag.
  • expandable (bool) = False: Whether the quote can be expanded.
  • escape_html (bool) = True: Whether to escape HTML.

Returns: str - Generated HTML tag for a blockquote.

Example:

bq('This is a blockquote.', expandable=True)

b

Creates an HTML tag for bold text.

Arguments:

  • text (str): Text to place inside the tag.
  • escape_html (bool) = True: Whether to escape HTML.

Returns: str - Generated HTML tag for bold text.

Example:

b('Bold text')

i

Creates an HTML tag for italic text.

Arguments:

  • text (str): Text to place inside the tag.
  • escape_html (bool) = True: Whether to escape HTML.

Returns: str - Generated HTML tag for italic text.

Example:

i('Italic text')

a

Creates an HTML tag for a hyperlink.

Arguments:

  • text (str): Link text.
  • url (str) = "": URL for the link.
  • escape_html (bool) = True: Whether to escape HTML.

Returns: str - Generated HTML tag for a hyperlink.

Example:

a('Click Here', 'https://example.com')

u

Creates an HTML tag for underlined text.

Arguments:

  • text (str): Text to place inside the tag.
  • escape_html (bool) = True: Whether to escape HTML.

Returns: str - Generated HTML tag for underlined text.

Example:

u('Underlined text')

s

Creates an HTML tag for strikethrough text.

Arguments:

  • text (str): Text to place inside the tag.
  • escape_html (bool) = True: Whether to escape HTML.

Returns: str - Generated HTML tag for strikethrough text.

Example:

s('Strikethrough text')

spoiler

Creates an HTML tag for a spoiler.

Arguments:

  • text (str): Text to place inside the tag.
  • escape_html (bool) = True: Whether to escape HTML.

Returns: str - Generated HTML tag for a spoiler.

Example:

spoiler('This is a spoiler')

emoji

Creates an HTML tag for a premium emoji.

Arguments:

  • id (int): ID of the custom emoji.
  • emoticon (str): Standard emoji to display if the user doesn't have Telegram Premium.

Returns: str - Generated HTML tag for the custom emoji.

Example:

emoji(5404799425245626483, "🌟")

remove_emoji_tags

Removes premium emojis from text.

Arguments:

  • text (str): Text containing emojis.

Returns: str - Text without emojis.

Example:

text_with_emojis = f"RimTUB {emoji(5404799425245626483, '🌟')}"
text = remove_emoji_tags(text_with_emojis)
# text = 'RimTUB 🌟'