Skip to content

Commit 6e4c63b

Browse files
authored
Merge pull request eternnoir#1549 from coder2020official/master
Set escape=True by default.
2 parents 03a567e + 42efb84 commit 6e4c63b

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

examples/asynchronous_telebot/formatting_example.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ async def start_message(message):
1010
message.chat.id,
1111
# function which connects all strings
1212
formatting.format_text(
13-
formatting.mbold(message.from_user.first_name, escape=True), # pass escape=True to escape special characters
14-
formatting.mitalic(message.from_user.first_name, escape=True),
15-
formatting.munderline(message.from_user.first_name, escape=True),
16-
formatting.mstrikethrough(message.from_user.first_name, escape=True),
17-
formatting.mcode(message.from_user.first_name, escape=True),
13+
formatting.mbold(message.from_user.first_name),
14+
formatting.mitalic(message.from_user.first_name),
15+
formatting.munderline(message.from_user.first_name),
16+
formatting.mstrikethrough(message.from_user.first_name),
17+
formatting.mcode(message.from_user.first_name),
1818
separator=" " # separator separates all strings
1919
),
2020
parse_mode='MarkdownV2'
@@ -23,19 +23,19 @@ async def start_message(message):
2323
# just a bold text using markdownv2
2424
await bot.send_message(
2525
message.chat.id,
26-
formatting.mbold(message.from_user.first_name, escape=True),
26+
formatting.mbold(message.from_user.first_name),
2727
parse_mode='MarkdownV2'
2828
)
2929

3030
# html
3131
await bot.send_message(
3232
message.chat.id,
3333
formatting.format_text(
34-
formatting.hbold(message.from_user.first_name, escape=True),
35-
formatting.hitalic(message.from_user.first_name, escape=True),
36-
formatting.hunderline(message.from_user.first_name, escape=True),
37-
formatting.hstrikethrough(message.from_user.first_name, escape=True),
38-
formatting.hcode(message.from_user.first_name, escape=True),
34+
formatting.hbold(message.from_user.first_name),
35+
formatting.hitalic(message.from_user.first_name),
36+
formatting.hunderline(message.from_user.first_name),
37+
formatting.hstrikethrough(message.from_user.first_name),
38+
formatting.hcode(message.from_user.first_name),
3939
separator=" "
4040
),
4141
parse_mode='HTML'
@@ -44,7 +44,7 @@ async def start_message(message):
4444
# just a bold text in html
4545
await bot.send_message(
4646
message.chat.id,
47-
formatting.hbold(message.from_user.first_name, escape=True),
47+
formatting.hbold(message.from_user.first_name),
4848
parse_mode='HTML'
4949
)
5050

examples/formatting_example.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ def start_message(message):
1010
message.chat.id,
1111
# function which connects all strings
1212
formatting.format_text(
13-
formatting.mbold(message.from_user.first_name, escape=True), # pass escape=True to escape special characters
14-
formatting.mitalic(message.from_user.first_name, escape=True),
15-
formatting.munderline(message.from_user.first_name, escape=True),
16-
formatting.mstrikethrough(message.from_user.first_name, escape=True),
17-
formatting.mcode(message.from_user.first_name, escape=True),
13+
formatting.mbold(message.from_user.first_name),
14+
formatting.mitalic(message.from_user.first_name),
15+
formatting.munderline(message.from_user.first_name),
16+
formatting.mstrikethrough(message.from_user.first_name),
17+
formatting.mcode(message.from_user.first_name),
1818
separator=" " # separator separates all strings
1919
),
2020
parse_mode='MarkdownV2'
@@ -23,19 +23,19 @@ def start_message(message):
2323
# just a bold text using markdownv2
2424
bot.send_message(
2525
message.chat.id,
26-
formatting.mbold(message.from_user.first_name, escape=True),
26+
formatting.mbold(message.from_user.first_name),
2727
parse_mode='MarkdownV2'
2828
)
2929

3030
# html
3131
bot.send_message(
3232
message.chat.id,
3333
formatting.format_text(
34-
formatting.hbold(message.from_user.first_name, escape=True),
35-
formatting.hitalic(message.from_user.first_name, escape=True),
36-
formatting.hunderline(message.from_user.first_name, escape=True),
37-
formatting.hstrikethrough(message.from_user.first_name, escape=True),
38-
formatting.hcode(message.from_user.first_name, escape=True),
34+
formatting.hbold(message.from_user.first_name),
35+
formatting.hitalic(message.from_user.first_name),
36+
formatting.hunderline(message.from_user.first_name),
37+
formatting.hstrikethrough(message.from_user.first_name),
38+
formatting.hcode(message.from_user.first_name),
3939
separator=" "
4040
),
4141
parse_mode='HTML'
@@ -44,7 +44,7 @@ def start_message(message):
4444
# just a bold text in html
4545
bot.send_message(
4646
message.chat.id,
47-
formatting.hbold(message.from_user.first_name, escape=True),
47+
formatting.hbold(message.from_user.first_name),
4848
parse_mode='HTML'
4949
)
5050

telebot/formatting.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def escape_markdown(content: str) -> str:
4949
return reparse
5050

5151

52-
def mbold(content: str, escape: bool=False) -> str:
52+
def mbold(content: str, escape: bool=True) -> str:
5353
"""
5454
Returns a Markdown-formatted bold string.
5555
@@ -59,7 +59,7 @@ def mbold(content: str, escape: bool=False) -> str:
5959
return '*{}*'.format(escape_markdown(content) if escape else content)
6060

6161

62-
def hbold(content: str, escape: bool=False) -> str:
62+
def hbold(content: str, escape: bool=True) -> str:
6363
"""
6464
Returns an HTML-formatted bold string.
6565
@@ -69,7 +69,7 @@ def hbold(content: str, escape: bool=False) -> str:
6969
return '<b>{}</b>'.format(escape_html(content) if escape else content)
7070

7171

72-
def mitalic(content: str, escape: bool=False) -> str:
72+
def mitalic(content: str, escape: bool=True) -> str:
7373
"""
7474
Returns a Markdown-formatted italic string.
7575
@@ -79,7 +79,7 @@ def mitalic(content: str, escape: bool=False) -> str:
7979
return '_{}_\r'.format(escape_markdown(content) if escape else content)
8080

8181

82-
def hitalic(content: str, escape: bool=False) -> str:
82+
def hitalic(content: str, escape: bool=True) -> str:
8383
"""
8484
Returns an HTML-formatted italic string.
8585
@@ -89,7 +89,7 @@ def hitalic(content: str, escape: bool=False) -> str:
8989
return '<i>{}</i>'.format(escape_html(content) if escape else content)
9090

9191

92-
def munderline(content: str, escape: bool=False) -> str:
92+
def munderline(content: str, escape: bool=True) -> str:
9393
"""
9494
Returns a Markdown-formatted underline string.
9595
@@ -99,7 +99,7 @@ def munderline(content: str, escape: bool=False) -> str:
9999
return '__{}__'.format(escape_markdown(content) if escape else content)
100100

101101

102-
def hunderline(content: str, escape: bool=False) -> str:
102+
def hunderline(content: str, escape: bool=True) -> str:
103103
"""
104104
Returns an HTML-formatted underline string.
105105
@@ -109,7 +109,7 @@ def hunderline(content: str, escape: bool=False) -> str:
109109
return '<u>{}</u>'.format(escape_html(content) if escape else content)
110110

111111

112-
def mstrikethrough(content: str, escape: bool=False) -> str:
112+
def mstrikethrough(content: str, escape: bool=True) -> str:
113113
"""
114114
Returns a Markdown-formatted strikethrough string.
115115
@@ -119,7 +119,7 @@ def mstrikethrough(content: str, escape: bool=False) -> str:
119119
return '~{}~'.format(escape_markdown(content) if escape else content)
120120

121121

122-
def hstrikethrough(content: str, escape: bool=False) -> str:
122+
def hstrikethrough(content: str, escape: bool=True) -> str:
123123
"""
124124
Returns an HTML-formatted strikethrough string.
125125
@@ -129,7 +129,7 @@ def hstrikethrough(content: str, escape: bool=False) -> str:
129129
return '<s>{}</s>'.format(escape_html(content) if escape else content)
130130

131131

132-
def mspoiler(content: str, escape: bool=False) -> str:
132+
def mspoiler(content: str, escape: bool=True) -> str:
133133
"""
134134
Returns a Markdown-formatted spoiler string.
135135
@@ -139,7 +139,7 @@ def mspoiler(content: str, escape: bool=False) -> str:
139139
return '||{}||'.format(escape_markdown(content) if escape else content)
140140

141141

142-
def hspoiler(content: str, escape: bool=False) -> str:
142+
def hspoiler(content: str, escape: bool=True) -> str:
143143
"""
144144
Returns an HTML-formatted spoiler string.
145145
@@ -149,7 +149,7 @@ def hspoiler(content: str, escape: bool=False) -> str:
149149
return '<tg-spoiler>{}</tg-spoiler>'.format(escape_html(content) if escape else content)
150150

151151

152-
def mlink(content: str, url: str, escape: bool=False) -> str:
152+
def mlink(content: str, url: str, escape: bool=True) -> str:
153153
"""
154154
Returns a Markdown-formatted link string.
155155
@@ -160,7 +160,7 @@ def mlink(content: str, url: str, escape: bool=False) -> str:
160160
return '[{}]({})'.format(escape_markdown(content), escape_markdown(url) if escape else content)
161161

162162

163-
def hlink(content: str, url: str, escape: bool=False) -> str:
163+
def hlink(content: str, url: str, escape: bool=True) -> str:
164164
"""
165165
Returns an HTML-formatted link string.
166166
@@ -171,7 +171,7 @@ def hlink(content: str, url: str, escape: bool=False) -> str:
171171
return '<a href="{}">{}</a>'.format(escape_html(url), escape_html(content) if escape else content)
172172

173173

174-
def mcode(content: str, language: str="", escape: bool=False) -> str:
174+
def mcode(content: str, language: str="", escape: bool=True) -> str:
175175
"""
176176
Returns a Markdown-formatted code string.
177177
@@ -181,7 +181,7 @@ def mcode(content: str, language: str="", escape: bool=False) -> str:
181181
return '```{}\n{}```'.format(language, escape_markdown(content) if escape else content)
182182

183183

184-
def hcode(content: str, escape: bool=False) -> str:
184+
def hcode(content: str, escape: bool=True) -> str:
185185
"""
186186
Returns an HTML-formatted code string.
187187
@@ -191,7 +191,7 @@ def hcode(content: str, escape: bool=False) -> str:
191191
return '<code>{}</code>'.format(escape_html(content) if escape else content)
192192

193193

194-
def hpre(content: str, escape: bool=False, language: str="") -> str:
194+
def hpre(content: str, escape: bool=True, language: str="") -> str:
195195
"""
196196
Returns an HTML-formatted preformatted string.
197197

0 commit comments

Comments
 (0)