2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-23 10:28:00 +00:00

Update TextFormatting.rst

This commit is contained in:
Dan 2018-05-12 14:15:16 +02:00
parent 0367c765e2
commit ea5853af18

View File

@ -1,8 +1,8 @@
Text Formatting Text Formatting
=============== ===============
Pyrogram, just like `Telegram Bot API`_, supports basic Markdown and HTML formatting styles for messages and media captions; Pyrogram, just like `Telegram Bot API`_, supports basic Markdown and HTML formatting styles for text messages and
Markdown uses the same syntax as Telegram Desktop's and is enabled by default. media captions; Markdown uses the same syntax as Telegram Desktop's and is enabled by default.
Beside bold, italic, and pre-formatted code, **Pyrogram does also support inline URLs and inline mentions of users**. Beside bold, italic, and pre-formatted code, **Pyrogram does also support inline URLs and inline mentions of users**.
Markdown Style Markdown Style
@ -11,15 +11,15 @@ Markdown Style
To use this mode, pass :obj:`MARKDOWN <pyrogram.ParseMode.MARKDOWN>` or "markdown" in the *parse_mode* field when using To use this mode, pass :obj:`MARKDOWN <pyrogram.ParseMode.MARKDOWN>` or "markdown" in the *parse_mode* field when using
:obj:`send_message() <pyrogram.Client.send_message>`. Use the following syntax in your message: :obj:`send_message() <pyrogram.Client.send_message>`. Use the following syntax in your message:
.. code:: .. code-block:: txt
**bold text** **bold text**
__italic text__ __italic text__
[inline URL](http://www.example.com/) [inline URL](https://docs.pyrogram.ml/)
[inline mention of a user](tg://user?id=123456789) [inline mention of a user](tg://user?id=23122162)
`inline fixed-width code` `inline fixed-width code`
@ -27,78 +27,70 @@ To use this mode, pass :obj:`MARKDOWN <pyrogram.ParseMode.MARKDOWN>` or "markdow
pre-formatted fixed-width code block pre-formatted fixed-width code block
``` ```
HTML Style HTML Style
---------- ----------
To use this mode, pass :obj:`HTML <pyrogram.ParseMode.HTML>` or "html" in the *parse_mode* field when using To use this mode, pass :obj:`HTML <pyrogram.ParseMode.HTML>` or "html" in the *parse_mode* field when using
:obj:`send_message() <pyrogram.Client.send_message>`. The following tags are currently supported: :obj:`send_message() <pyrogram.Client.send_message>`. The following tags are currently supported:
.. code:: .. code-block:: txt
<b>bold</b>, <strong>bold</strong> <b>bold</b>, <strong>bold</strong>
<i>italic</i>, <em>italic</em> <i>italic</i>, <em>italic</em>
<a href="http://www.example.com/">inline URL</a> <a href="http://docs.pyrogram.ml/">inline URL</a>
<a href="tg://user?id=123456789">inline mention of a user</a> <a href="tg://user?id=23122162">inline mention of a user</a>
<code>inline fixed-width code</code> <code>inline fixed-width code</code>
<pre>pre-formatted fixed-width code block</pre> <pre>pre-formatted fixed-width
code block
</pre>
.. note:: Mentions are only guaranteed to work if you have already contacted the user. .. note:: Mentions are only guaranteed to work if you have already met the user (in groups or private chats).
Examples Examples
-------- --------
- Markdown inline entities (bold, italic, ...): - Markdown:
.. code-block:: python .. code-block:: python
app.send_message( app.send_message(
chat_id="me", chat_id="haskell",
text=( text=(
"**bold**, " "**bold**, "
"__italic__, " "__italic__, "
"[mention](tg://user?id=23122162), " "[mention](tg://user?id=23122162), "
"[url](https://pyrogram.ml), " "[URL](https://docs.pyrogram.ml), "
"`code`" "`code`, "
)
)
- Markdown code blocks:
.. code-block:: python
app.send_message(
chat_id="me",
text=(
# Code block language is optional
"``` python\n"
"for i in range(10):\n"
" print(i)\n"
"```" "```"
"for i in range(10):\n"
" print(i)```"
) )
) )
- HTML example: - HTML:
.. code-block:: python .. code-block:: python
from pyrogram import ParseMode
app.send_message( app.send_message(
chat_id="me", chat_id="haskell",
text=( text=(
"<b>bold</b>, <strong>bold</strong>, " "<b>bold</b>, "
"<i>italic</i>, <em>italic</em>, " "<i>italic</i>, "
"<a href=\"https://pyrogram.ml/\">inline URL</a>, " "<a href=\"tg://user?id=23122162\">mention</a>, "
"<a href=\"tg://user?id=23122162\">inline mention of a user</a>, " "<a href=\"https://pyrogram.ml/\">URL</a>, "
"<code>inline fixed-width code</code>, " "<code>code</code>, "
"<pre>pre-formatted fixed-width code block</pre>" "<pre>"
"for i in range(10):\n"
" print(i)"
"</pre>"
), ),
parse_mode=ParseMode.HTML parse_mode="html"
) )
.. _Telegram Bot API: https://core.telegram.org/bots/api#formatting-options .. _Telegram Bot API: https://core.telegram.org/bots/api#formatting-options