From 11b240937dfc52aff4a17b86581b8ebdd326a6df Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Tue, 23 Jan 2018 16:14:43 +0100 Subject: [PATCH] Update docs --- docs/source/pyrogram/ParseMode.rst | 6 +++ docs/source/pyrogram/index.rst | 1 + docs/source/resources/TextFormatting.rst | 69 ++++++++++++++++++++---- 3 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 docs/source/pyrogram/ParseMode.rst diff --git a/docs/source/pyrogram/ParseMode.rst b/docs/source/pyrogram/ParseMode.rst new file mode 100644 index 00000000..6a4e0bbb --- /dev/null +++ b/docs/source/pyrogram/ParseMode.rst @@ -0,0 +1,6 @@ +ParseMode +========= + +.. autoclass:: pyrogram.ParseMode + :members: + :undoc-members: diff --git a/docs/source/pyrogram/index.rst b/docs/source/pyrogram/index.rst index 3ea4ae8f..e484bd5e 100644 --- a/docs/source/pyrogram/index.rst +++ b/docs/source/pyrogram/index.rst @@ -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 diff --git a/docs/source/resources/TextFormatting.rst b/docs/source/resources/TextFormatting.rst index 07651d9c..d17ab8e8 100644 --- a/docs/source/resources/TextFormatting.rst +++ b/docs/source/resources/TextFormatting.rst @@ -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 `. 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 `. The following tags are currently supported: + +.. code:: + + bold, bold + + italic, italic + + inline URL + + inline mention of a user + + inline fixed-width code + +
pre-formatted fixed-width code block
+ +.. 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=( + "bold, bold\n" + "italic, italic\n" + "inline URL\n" + "inline mention of a user\n" + "inline fixed-width code\n" + "
pre-formatted fixed-width code block
\n" + ), + parse_mode=ParseMode.HTML + ) + .. _Telegram Bot API: https://core.telegram.org/bots/api#formatting-options \ No newline at end of file