2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-28 12:57:52 +00:00

Merge branch 'master' into docs

This commit is contained in:
Dan 2018-01-23 16:15:32 +01:00
commit 8f1e4b41cb
4 changed files with 74 additions and 18 deletions

View File

@ -0,0 +1,6 @@
ParseMode
=========
.. autoclass:: pyrogram.ParseMode
:members:
:undoc-members:

View File

@ -10,6 +10,7 @@ the same parameters as well, thus offering a familiar look to Bot developers.
.. toctree::
Client
ChatAction
ParseMode
Error
.. _Telegram Bot API: https://core.telegram.org/bots/api#available-methods

View File

@ -1,11 +1,15 @@
Text Formatting
===============
Pyrogram, just like `Telegram Bot API`_, supports basic Markdown formatting for messages;
it uses the same syntax as Telegram Desktop's and is enabled by default.
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.
Beside bold, italic, and pre-formatted code, **Pyrogram does also support inline URLs and inline mentions of users**.
Here is the complete syntax you can use when sending or editing messages:
Markdown Style
--------------
To use this mode, pass :obj:`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:
.. code::
@ -23,21 +27,47 @@ Here is the complete syntax you can use when sending or editing messages:
pre-formatted fixed-width code block
```
Code Snippets
-------------
HTML Style
----------
- Inline entities (bold, italic, ...):
To use this mode, pass :obj:`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:
.. 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
--------
- Markdown inline entities (bold, italic, ...):
.. code-block:: python
client.send_message(
chat_id="me",
text="**bold**, __italic__, [mention](tg://user?id=23122162), [url](https://pyrogram.ml), `code`"
text=(
"**bold**\n"
"__italic__\n"
"[mention](tg://user?id=23122162)\n"
"[url](https://pyrogram.ml)\n"
"`code`\n"
)
)
.. note:: Mentions are only guaranteed to work if you have already contacted the user.
- Code blocks:
- Markdown code blocks:
.. code-block:: python
@ -52,4 +82,23 @@ Code Snippets
)
)
- HTML example:
.. code-block:: python
from pyrogram import ParseMode
client.send_message(
chat_id="me",
text=(
"<b>bold</b>, <strong>bold</strong>\n"
"<i>italic</i>, <em>italic</em>\n"
"<a href=\"https://pyrogram.ml/\">inline URL</a>\n"
"<a href=\"tg://user?id=23122162\">inline mention of a user</a>\n"
"<code>inline fixed-width code</code>\n"
"<pre>pre-formatted fixed-width code block</pre>\n"
),
parse_mode=ParseMode.HTML
)
.. _Telegram Bot API: https://core.telegram.org/bots/api#formatting-options

View File

@ -490,7 +490,7 @@ class Client:
parse_mode (:obj:`str`):
Use :obj:`pyrogram.ParseMode.MARKDOWN` or :obj:`pyrogram.ParseMode.HTML` if you want Telegram apps
to show bold, italic, fixed-width text or inline URLs in your message.
Defaults to MARKDOWN.
Defaults to Markdown.
disable_web_page_preview (:obj:`bool`, optional):
Disables link previews for links in this message.
@ -588,7 +588,7 @@ class Client:
parse_mode (:obj:`str`):
Use :obj:`pyrogram.ParseMode.MARKDOWN` or :obj:`pyrogram.ParseMode.HTML` if you want Telegram apps
to show bold, italic, fixed-width text or inline URLs in your caption.
Defaults to MARKDOWN.
Defaults to Markdown.
ttl_seconds (:obj:`int`, optional):
Self-Destruct Timer.
@ -661,7 +661,7 @@ class Client:
parse_mode (:obj:`str`):
Use :obj:`pyrogram.ParseMode.MARKDOWN` or :obj:`pyrogram.ParseMode.HTML` if you want Telegram apps
to show bold, italic, fixed-width text or inline URLs in your caption.
Defaults to MARKDOWN.
Defaults to Markdown.
duration (:obj:`int`, optional):
Duration of the audio in seconds.
@ -741,7 +741,7 @@ class Client:
parse_mode (:obj:`str`):
Use :obj:`pyrogram.ParseMode.MARKDOWN` or :obj:`pyrogram.ParseMode.HTML` if you want Telegram apps
to show bold, italic, fixed-width text or inline URLs in your caption.
Defaults to MARKDOWN.
Defaults to Markdown.
disable_notification (:obj:`bool`, optional):
Sends the message silently.
@ -810,7 +810,7 @@ class Client:
parse_mode (:obj:`str`):
Use :obj:`pyrogram.ParseMode.MARKDOWN` or :obj:`pyrogram.ParseMode.HTML` if you want Telegram apps
to show bold, italic, fixed-width text or inline URLs in your caption.
Defaults to MARKDOWN.
Defaults to Markdown.
duration (:obj:`int`, optional):
Duration of sent video in seconds.
@ -890,7 +890,7 @@ class Client:
parse_mode (:obj:`str`):
Use :obj:`pyrogram.ParseMode.MARKDOWN` or :obj:`pyrogram.ParseMode.HTML` if you want Telegram apps
to show bold, italic, fixed-width text or inline URLs in your caption.
Defaults to MARKDOWN.
Defaults to Markdown.
duration (:obj:`int`, optional):
Duration of the voice message in seconds.
@ -1255,7 +1255,7 @@ class Client:
parse_mode (:obj:`str`):
Use :obj:`pyrogram.ParseMode.MARKDOWN` or :obj:`pyrogram.ParseMode.HTML` if you want Telegram apps
to show bold, italic, fixed-width text or inline URLs in your message.
Defaults to MARKDOWN.
Defaults to Markdown.
disable_web_page_preview (:obj:`bool`, optional):
Disables link previews for links in this message.
@ -1296,7 +1296,7 @@ class Client:
parse_mode (:obj:`str`):
Use :obj:`pyrogram.ParseMode.MARKDOWN` or :obj:`pyrogram.ParseMode.HTML` if you want Telegram apps
to show bold, italic, fixed-width text or inline URLs in your caption.
Defaults to MARKDOWN.
Defaults to Markdown.
Raises:
:class:`pyrogram.Error`