MTPyroger/docs/source/resources/TextFormatting.rst

104 lines
2.8 KiB
ReStructuredText
Raw Normal View History

2018-01-06 11:18:15 +00:00
Text Formatting
===============
2018-01-23 15:14:43 +00:00
Pyrogram, just like `Telegram Bot API`_, supports basic Markdown and HTML formatting styles for 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
.. code::
**bold text**
__italic text__
[inline URL](http://www.example.com/)
[inline mention of a user](tg://user?id=123456789)
`inline fixed-width code`
```block_language
pre-formatted fixed-width code block
```
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
.. code::
<b>bold</b>, <strong>bold</strong>
<i>italic</i>, <em>italic</em>
<a href="http://www.example.com/">inline URL</a>
<a href="tg://user?id=123456789">inline mention of a user</a>
<code>inline fixed-width code</code>
<pre>pre-formatted fixed-width code block</pre>
.. note:: Mentions are only guaranteed to work if you have already contacted the user.
Examples
--------
2018-01-06 11:18:15 +00:00
2018-01-23 15:14:43 +00:00
- Markdown inline entities (bold, italic, ...):
2018-01-06 11:18:15 +00:00
.. code-block:: python
app.send_message(
2018-01-06 11:18:15 +00:00
chat_id="me",
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://pyrogram.ml), "
"`code`"
2018-01-23 15:14:43 +00:00
)
2018-01-06 11:18:15 +00:00
)
2018-01-23 15:14:43 +00:00
- Markdown code blocks:
2018-01-06 11:18:15 +00:00
.. code-block:: python
app.send_message(
2018-01-06 11:18:15 +00:00
chat_id="me",
text=(
# Code block language is optional
"``` python\n"
"for i in range(10):\n"
" print(i)\n"
"```"
)
)
2018-01-23 15:14:43 +00:00
- HTML example:
.. code-block:: python
from pyrogram import ParseMode
app.send_message(
2018-01-23 15:14:43 +00:00
chat_id="me",
text=(
2018-01-24 21:17:12 +00:00
"<b>bold</b>, <strong>bold</strong>, "
"<i>italic</i>, <em>italic</em>, "
"<a href=\"https://pyrogram.ml/\">inline URL</a>, "
"<a href=\"tg://user?id=23122162\">inline mention of a user</a>, "
"<code>inline fixed-width code</code>, "
"<pre>pre-formatted fixed-width code block</pre>"
2018-01-23 15:14:43 +00:00
),
parse_mode=ParseMode.HTML
)
2018-01-06 11:18:15 +00:00
.. _Telegram Bot API: https://core.telegram.org/bots/api#formatting-options