MTPyroger/docs/source/topics/text-formatting.rst

97 lines
2.4 KiB
ReStructuredText
Raw Normal View History

2018-01-06 11:18:15 +00:00
Text Formatting
===============
2018-07-29 01:40:04 +00:00
Pyrogram, just like the `Telegram Bot API`_, natively supports basic Markdown and HTML formatting styles for text
messages and media captions.
Markdown style uses the same syntax as Telegram Desktop's and is enabled by default.
2018-01-06 11:18:15 +00:00
Beside bold, italic, and pre-formatted code, **Pyrogram does also support inline URLs and inline mentions of users**.
2018-01-23 15:14:43 +00:00
Markdown Style
--------------
2019-05-12 17:26:55 +00:00
To use this mode, pass "markdown" in the *parse_mode* field when using
2019-05-28 14:41:55 +00:00
:meth:`~pyrogram.Client.send_message`. Use the following syntax in your message:
2018-01-06 11:18:15 +00:00
2018-07-29 01:37:50 +00:00
.. code-block:: text
2018-01-06 11:18:15 +00:00
**bold text**
__italic text__
[inline URL](https://docs.pyrogram.org/)
2018-01-06 11:18:15 +00:00
2018-05-12 12:15:16 +00:00
[inline mention of a user](tg://user?id=23122162)
2018-01-06 11:18:15 +00:00
`inline fixed-width code`
```block_language
pre-formatted fixed-width code block
```
2018-05-12 12:15:16 +00:00
2018-01-23 15:14:43 +00:00
HTML Style
----------
2019-05-28 14:41:55 +00:00
To use this mode, pass "html" in the *parse_mode* field when using :meth:`~pyrogram.Client.send_message`.
2019-05-12 17:26:55 +00:00
The following tags are currently supported:
2018-01-23 15:14:43 +00:00
2018-07-29 01:37:50 +00:00
.. code-block:: text
2018-01-23 15:14:43 +00:00
<b>bold</b>, <strong>bold</strong>
<i>italic</i>, <em>italic</em>
<a href="http://docs.pyrogram.org/">inline URL</a>
2018-01-23 15:14:43 +00:00
2018-05-12 12:15:16 +00:00
<a href="tg://user?id=23122162">inline mention of a user</a>
2018-01-23 15:14:43 +00:00
<code>inline fixed-width code</code>
2018-07-29 01:38:30 +00:00
<pre>pre-formatted fixed-width code block</pre>
2018-01-23 15:14:43 +00:00
2018-05-12 12:15:16 +00:00
.. note:: Mentions are only guaranteed to work if you have already met the user (in groups or private chats).
2018-01-23 15:14:43 +00:00
Examples
--------
2018-01-06 11:18:15 +00:00
2018-05-12 12:15:16 +00:00
- Markdown:
2018-01-06 11:18:15 +00:00
.. code-block:: python
app.send_message(
2018-05-12 12:15:16 +00:00
chat_id="haskell",
2018-01-23 15:14:43 +00:00
text=(
2018-01-24 21:17:12 +00:00
"**bold**, "
"__italic__, "
"[mention](tg://user?id=23122162), "
"[URL](https://docs.pyrogram.org), "
2018-05-12 12:15:16 +00:00
"`code`, "
2018-01-06 11:18:15 +00:00
"```"
2018-05-12 12:15:16 +00:00
"for i in range(10):\n"
" print(i)```"
2018-01-06 11:18:15 +00:00
)
)
2018-05-12 12:15:16 +00:00
- HTML:
2018-01-23 15:14:43 +00:00
.. code-block:: python
app.send_message(
2018-05-12 12:15:16 +00:00
chat_id="haskell",
2018-01-23 15:14:43 +00:00
text=(
2018-05-12 12:15:16 +00:00
"<b>bold</b>, "
"<i>italic</i>, "
"<a href=\"tg://user?id=23122162\">mention</a>, "
"<a href=\"https://pyrogram.org/\">URL</a>, "
2018-05-12 12:15:16 +00:00
"<code>code</code>, "
"<pre>"
"for i in range(10):\n"
" print(i)"
"</pre>"
2018-01-23 15:14:43 +00:00
),
2018-05-12 12:15:16 +00:00
parse_mode="html"
2018-01-23 15:14:43 +00:00
)
2018-01-06 11:18:15 +00:00
.. _Telegram Bot API: https://core.telegram.org/bots/api#formatting-options