@@ -17,6 +17,8 @@ Pyrogram uses a custom Markdown dialect for text formatting which adds some uniq
1717texts easier in both Markdown and HTML. You can send sophisticated text messages and media captions using a
1818variety of decorations that can also be nested in order to combine multiple styles together.
1919
20+ `The official BOT API style HTML formatting is also supported <https://core.telegram.org/bots/api#html-style >`__
21+
2022
2123-----
2224
@@ -40,7 +42,97 @@ list of the basic styles currently supported by Pyrogram.
4042- spoiler
4143- `text URL <https://telegramplayground.github.io/pyrogram/ >`_
4244- `user text mention <tg://user?id=123456789 >`_
45+ - :emoji: `👍 `
46+
47+
48+ HTML Style
49+ ----------
50+
51+ To strictly use this mode, pass :obj: `~pyrogram.enums.HTML ` to the *parse_mode * parameter when using
52+ :meth: `~pyrogram.Client.send_message `. The following tags are currently supported:
53+
54+ .. code-block :: text
55+
56+ <b>bold</b>, <strong>bold</strong>
57+
58+ <i>italic</i>, <em>italic</em>
59+
60+ <u>underline</u>
61+
62+ <s>strike</s>, <del>strike</del>, <strike>strike</strike>
63+
64+ <tg-spoiler>spoiler</tg-spoiler>
65+
66+ <a href="https://telegramplayground.github.io/pyrogram/">text URL</a>
67+
68+ <a href="tg://user?id=123456789">inline mention</a>
69+
70+ <code>inline fixed-width code</code>
71+
72+ <tg-emoji emoji-id="5469770542288478598">👍</tg-emoji>
73+
74+ <pre>
75+ <code class="language-python">
76+ pre-formatted fixed-width code block written in the Python programming language
77+ </code>
78+ </pre>
79+
80+ **Example **:
4381
82+ .. code-block :: python
83+
84+ from pyrogram.enums import ParseMode
85+
86+ await app.send_message(
87+ chat_id = " me" ,
88+ text = (
89+ " <b>bold</b>, <strong>bold</strong>"
90+ " <i>italic</i>, <em>italic</em>"
91+ " <u>underline</u>, <ins>underline</ins>"
92+ " <s>strike</s>, <strike>strike</strike>, <del>strike</del>"
93+ " <tg-spoiler>spoiler</tg-spoiler>\n\n "
94+
95+ " <b>bold <i>italic bold <s>italic bold strike <tg-spoiler>italic bold strike spoiler</tg-spoiler></s> <u>underline italic bold</u></i> bold</b>\n\n "
96+
97+ " <a href=\" https://telegramplayground.github.io/pyrogram/\" >inline URL</a> "
98+ " <a href=\" tg://user?id=23122162\" >inline mention of a user</a>\n "
99+ " <tg-emoji emoji-id=5469770542288478598>👍</tg-emoji> "
100+ " <code>inline fixed-width code</code> "
101+ " <pre>pre-formatted fixed-width code block</pre>\n\n "
102+ " </pre><code class='language-python'>"
103+ " for i in range(10):\n "
104+ " print(i)"
105+ " </code></pre>\n\n "
106+
107+ " <blockquote>Block quotation started"
108+ " Block quotation continued"
109+ " The last line of the block quotation</blockquote>"
110+ " <blockquote expandable>Expandable block quotation started"
111+ " Expandable block quotation continued"
112+ " Expandable block quotation continued"
113+ " Hidden by default part of the block quotation started"
114+ " Expandable block quotation continued"
115+ " The last line of the block quotation</blockquote>"
116+ ),
117+ parse_mode = ParseMode.HTML
118+ )
119+
120+ .. note ::
121+
122+ All ``< ``, ``> `` and ``& `` symbols that are not a part of a tag or an HTML entity must be replaced with the
123+ corresponding HTML entities (``< `` with ``< ``, ``> `` with ``> `` and ``& `` with ``& ``). You can use this
124+ snippet to quickly escape those characters:
125+
126+ .. code-block :: python
127+
128+ text = " <my & text>"
129+ text = text.replace(" <" , " <" ).replace(" &" , " &" )
130+
131+ print (text)
132+
133+ .. code-block :: text
134+
135+ <my & text>
44136
45137
46138 Markdown Style
@@ -107,11 +199,12 @@ To strictly use this mode, pass :obj:`~pyrogram.enums.ParseMode.MARKDOWN` to the
107199 " ~~strike~~, "
108200 " ||spoiler||, "
109201 " [URL](https://telegramplayground.github.io/pyrogram/), "
202+ " "
110203 " `code`, "
111- " ```"
204+ " ```py "
112205 " for i in range(10):\n "
113206 " print(i)"
114- " ```"
207+ " ```\n "
115208
116209 " >blockquote\n "
117210
@@ -135,96 +228,6 @@ To strictly use this mode, pass :obj:`~pyrogram.enums.ParseMode.MARKDOWN` to the
135228 parse_mode = ParseMode.MARKDOWN
136229 )
137230
138- HTML Style
139- ----------
140-
141- To strictly use this mode, pass :obj: `~pyrogram.enums.HTML ` to the *parse_mode * parameter when using
142- :meth: `~pyrogram.Client.send_message `. The following tags are currently supported:
143-
144- .. code-block :: text
145-
146- <b>bold</b>, <strong>bold</strong>
147-
148- <i>italic</i>, <em>italic</em>
149-
150- <u>underline</u>
151-
152- <s>strike</s>, <del>strike</del>, <strike>strike</strike>
153-
154- <spoiler>spoiler</spoiler>
155-
156- <a href="https://telegramplayground.github.io/pyrogram/">text URL</a>
157-
158- <a href="tg://user?id=123456789">inline mention</a>
159-
160- <code>inline fixed-width code</code>
161-
162- <emoji id="12345678901234567890">🔥</emoji>
163-
164- <pre language="py">
165- pre-formatted
166- fixed-width
167- code block
168- </pre>
169-
170- **Example **:
171-
172- .. code-block :: python
173-
174- from pyrogram.enums import ParseMode
175-
176- await app.send_message(
177- chat_id = " me" ,
178- text = (
179- " <b>bold</b>, <strong>bold</strong>"
180- " <i>italic</i>, <em>italic</em>"
181- " <u>underline</u>, <ins>underline</ins>"
182- " <s>strike</s>, <strike>strike</strike>, <del>strike</del>"
183- " <spoiler>spoiler</spoiler>\n\n "
184-
185- " <b>bold <i>italic bold <s>italic bold strike <spoiler>italic bold strike spoiler</spoiler></s> <u>underline italic bold</u></i> bold</b>\n\n "
186-
187- " <a href=\" https://telegramplayground.github.io/pyrogram/\" >inline URL</a> "
188- " <a href=\" tg://user?id=23122162\" >inline mention of a user</a>\n "
189- " <emoji id=5368324170671202286>👍</emoji> "
190- " <code>inline fixed-width code</code> "
191- " <pre>pre-formatted fixed-width code block</pre>\n\n "
192- " <pre language='py'>"
193- " for i in range(10):\n "
194- " print(i)"
195- " </pre>\n\n "
196-
197- " <blockquote>Block quotation started"
198- " Block quotation continued"
199- " The last line of the block quotation</blockquote>"
200- " <blockquote expandable>Expandable block quotation started"
201- " Expandable block quotation continued"
202- " Expandable block quotation continued"
203- " Hidden by default part of the block quotation started"
204- " Expandable block quotation continued"
205- " The last line of the block quotation</blockquote>"
206- ),
207- parse_mode = ParseMode.HTML
208- )
209-
210- .. note ::
211-
212- All ``< ``, ``> `` and ``& `` symbols that are not a part of a tag or an HTML entity must be replaced with the
213- corresponding HTML entities (``< `` with ``< ``, ``> `` with ``> `` and ``& `` with ``& ``). You can use this
214- snippet to quickly escape those characters:
215-
216- .. code-block :: python
217-
218- import html
219-
220- text = " <my text>"
221- text = html.escape(text)
222-
223- print (text)
224-
225- .. code-block :: text
226-
227- <my text>
228231
229232 Different Styles
230233----------------
@@ -272,6 +275,13 @@ Result:
272275Nested and Overlapping Entities
273276-------------------------------
274277
278+ .. warning ::
279+
280+ The Markdown style is not recommended for complex text formatting.
281+
282+ If you want to use complex text formatting such as nested entities, overlapping entities use the HTML style instead.
283+
284+
275285You can also style texts with more than one decoration at once by nesting entities together. For example, you can send
276286a text message with both :bold-underline: `bold and underline ` styles, or a text that has both :strike-italic: `italic and
277287strike ` styles, and you can still combine both Markdown and HTML together.
0 commit comments