Skip to content

Commit

Permalink
Add a way to disable the syntax detector (fixes #27)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Pietro Albini committed Feb 24, 2016
1 parent 4820507 commit 7dc390e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion botogram/syntaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def guess_syntax(message, provided):
else:
return None

if provided in ("md", "markdown", "Markdown"):
if provided in ("plain",):
return None
elif provided in ("md", "markdown", "Markdown"):
return "Markdown"
elif provided in ("html", "HTML"):
return "HTML"
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ botogram 0.1.2

*Bugfix release, not yet released*

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

.. _issue 27: https://github.com/pietroalbini/botogram/issues/27
.. _issue 28: https://github.com/pietroalbini/botogram/issues/28

.. _changelog-0.1.1:
Expand Down
7 changes: 7 additions & 0 deletions docs/tricks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ That parameter accepts the following values:
* ``markdown``, or its aliases ``md`` and ``Markdown``
* ``html``, or its alias ``HTML``

Also, if you don't want to use any rich formatting but the detector spots
something, you can disable it providing the special syntax ``plain`` to it:

.. code-block:: python
chat.send("*I don't want this to be detected*", syntax="plain")
.. note::

Support for rich formatting depends on your users' Telegram client. If
Expand Down
3 changes: 3 additions & 0 deletions tests/test_syntaxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def test_is_html():

def test_guess_syntax():
# Provided syntax name
for name in ("plain",):
assert botogram.syntaxes.guess_syntax("", name) is None

for name in ("md", "markdown", "Markdown"):
assert botogram.syntaxes.guess_syntax("", name) == "Markdown"

Expand Down

0 comments on commit 7dc390e

Please sign in to comment.