MTPyroger/docs/source/resources/TextFormatting.rst

96 lines
2.5 KiB
ReStructuredText
Raw Normal View History

2018-01-06 11:18:15 +00:00
Text Formatting
===============
2018-05-12 12:15:16 +00:00
Pyrogram, just like `Telegram Bot API`_, supports basic Markdown and HTML formatting styles for text messages and
media captions; Markdown 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
--------------
2018-03-25 19:30:39 +00:00
To use this mode, pass :obj:`MARKDOWN <pyrogram.ParseMode.MARKDOWN>` or "markdown" in the *parse_mode* field when using
2018-04-11 21:18:17 +00:00
:obj:`send_message() <pyrogram.Client.send_message>`. Use the following syntax in your message:
2018-01-06 11:18:15 +00:00
2018-05-12 12:15:16 +00:00
.. code-block:: txt
2018-01-06 11:18:15 +00:00
**bold text**
__italic text__
2018-05-12 12:15:16 +00:00
[inline URL](https://docs.pyrogram.ml/)
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
----------
2018-03-25 19:30:39 +00:00
To use this mode, pass :obj:`HTML <pyrogram.ParseMode.HTML>` or "html" in the *parse_mode* field when using
2018-04-11 21:18:17 +00:00
:obj:`send_message() <pyrogram.Client.send_message>`. The following tags are currently supported:
2018-01-23 15:14:43 +00:00
2018-05-12 12:15:16 +00:00
.. code-block:: txt
2018-01-23 15:14:43 +00:00
<b>bold</b>, <strong>bold</strong>
<i>italic</i>, <em>italic</em>
2018-05-12 12:15:16 +00:00
<a href="http://docs.pyrogram.ml/">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-05-12 12:15:16 +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), "
2018-05-12 12:15:16 +00:00
"[URL](https://docs.pyrogram.ml), "
"`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.ml/\">URL</a>, "
"<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