Skip to content

Commit 7dc390e

Browse files
author
Pietro Albini
committed
Add a way to disable the syntax detector (fixes #27)
Before this commit, there was no way to explicitly disable the automatic syntax detector. That is useful, for example, if it screws up and you don't want any syntax in your messages. This commit adds a special `plain` syntax which forces plain text.
1 parent 4820507 commit 7dc390e

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

botogram/syntaxes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def guess_syntax(message, provided):
5555
else:
5656
return None
5757

58-
if provided in ("md", "markdown", "Markdown"):
58+
if provided in ("plain",):
59+
return None
60+
elif provided in ("md", "markdown", "Markdown"):
5961
return "Markdown"
6062
elif provided in ("html", "HTML"):
6163
return "HTML"

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ botogram 0.1.2
2525

2626
*Bugfix release, not yet released*
2727

28+
* Add a way to disable the syntax detector (`issue 27`_)
2829
* Fix automatic syntax detector recognizing markdown in URLs (`issue 28`_)
2930

31+
.. _issue 27: https://github.com/pietroalbini/botogram/issues/27
3032
.. _issue 28: https://github.com/pietroalbini/botogram/issues/28
3133

3234
.. _changelog-0.1.1:

docs/tricks.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ That parameter accepts the following values:
7171
* ``markdown``, or its aliases ``md`` and ``Markdown``
7272
* ``html``, or its alias ``HTML``
7373

74+
Also, if you don't want to use any rich formatting but the detector spots
75+
something, you can disable it providing the special syntax ``plain`` to it:
76+
77+
.. code-block:: python
78+
79+
chat.send("*I don't want this to be detected*", syntax="plain")
80+
7481
.. note::
7582

7683
Support for rich formatting depends on your users' Telegram client. If

tests/test_syntaxes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def test_is_html():
4141

4242
def test_guess_syntax():
4343
# Provided syntax name
44+
for name in ("plain",):
45+
assert botogram.syntaxes.guess_syntax("", name) is None
46+
4447
for name in ("md", "markdown", "Markdown"):
4548
assert botogram.syntaxes.guess_syntax("", name) == "Markdown"
4649

0 commit comments

Comments
 (0)