Remove parse_mode from the client

This commit is contained in:
Lonami Exo 2021-10-16 13:59:33 +02:00
parent e2132d5f7c
commit 1b15a34f69
3 changed files with 6 additions and 56 deletions

View File

@ -207,8 +207,10 @@ The ``telethon.errors`` module continues to provide custom errors used by the li
// TODO provide a way to see which errors are known in the docs or at tl.telethon.dev
The default markdown parse mode now conforms to the commonmark specification
----------------------------------------------------------------------------
Changes to the default parse mode
---------------------------------
The default markdown parse mode now conforms to the commonmark specification.
The old markdown parser (which was used as the default ``client.parse_mode``) used to emulate
Telegram Desktop's behaviour. Now `<markdown-it-py https://github.com/executablebooks/markdown-it-py>`__
@ -224,6 +226,8 @@ Because now there's proper parsing, you also gain:
* Inline links should no longer behave in a strange manner.
* Pre-blocks can now have a language. Official clients don't syntax highlight code yet, though.
Furthermore, the parse mode is no longer client-dependant. It is now configured through ``Message``.
// TODO provide a way to get back the old behaviour?

View File

@ -10,16 +10,6 @@ if typing.TYPE_CHECKING:
from .telegramclient import TelegramClient
def get_parse_mode(self: 'TelegramClient'):
return self._parse_mode
def set_parse_mode(self: 'TelegramClient', mode: str):
self._parse_mode = utils.sanitize_parse_mode(mode)
# endregion
# region Private methods
async def _replace_with_mention(self: 'TelegramClient', entities, i, user):
"""
Helper method to replace ``entities[i]`` to mention ``user``,

View File

@ -1817,50 +1817,6 @@ class TelegramClient:
# endregion Downloads
# region Message parse
@property
def parse_mode(self: 'TelegramClient'):
"""
This property is the default parse mode used when sending messages.
Defaults to `telethon.extensions.markdown`. It will always
be either `None` or an object with ``parse`` and ``unparse``
methods.
When setting a different value it should be one of:
* Object with ``parse`` and ``unparse`` methods.
* A ``callable`` to act as the parse method.
* A `str` indicating the ``parse_mode``. For Markdown ``'md'``
or ``'markdown'`` may be used. For HTML, ``'htm'`` or ``'html'``
may be used.
The ``parse`` method should be a function accepting a single
parameter, the text to parse, and returning a tuple consisting
of ``(parsed message str, [MessageEntity instances])``.
The ``unparse`` method should be the inverse of ``parse`` such
that ``assert text == unparse(*parse(text))``.
See :tl:`MessageEntity` for allowed message entities.
Example
.. code-block:: python
# Disabling default formatting
client.parse_mode = None
# Enabling HTML as the default format
client.parse_mode = 'html'
"""
return messageparse.get_parse_mode(**locals())
@parse_mode.setter
def parse_mode(self: 'TelegramClient', mode: str):
return messageparse.set_parse_mode(**locals())
# endregion Message parse
# region Messages
@forward_call(messages.get_messages)