mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Add new message entities to markdown/html parsers
This commit is contained in:
parent
3c68208c41
commit
962949008f
|
@ -10,7 +10,8 @@ from .. import helpers
|
||||||
from ..tl.types import (
|
from ..tl.types import (
|
||||||
MessageEntityBold, MessageEntityItalic, MessageEntityCode,
|
MessageEntityBold, MessageEntityItalic, MessageEntityCode,
|
||||||
MessageEntityPre, MessageEntityEmail, MessageEntityUrl,
|
MessageEntityPre, MessageEntityEmail, MessageEntityUrl,
|
||||||
MessageEntityTextUrl, MessageEntityMentionName
|
MessageEntityTextUrl, MessageEntityMentionName,
|
||||||
|
MessageEntityUnderline, MessageEntityStrike, MessageEntityBlockquote
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +47,12 @@ class HTMLToTelegramParser(HTMLParser):
|
||||||
EntityType = MessageEntityBold
|
EntityType = MessageEntityBold
|
||||||
elif tag == 'em' or tag == 'i':
|
elif tag == 'em' or tag == 'i':
|
||||||
EntityType = MessageEntityItalic
|
EntityType = MessageEntityItalic
|
||||||
|
elif tag == 'u':
|
||||||
|
EntityType = MessageEntityUnderline
|
||||||
|
elif tag == 'del' or tag == 's':
|
||||||
|
EntityType = MessageEntityStrike
|
||||||
|
elif tag == 'blockquote':
|
||||||
|
EntityType = MessageEntityBlockquote
|
||||||
elif tag == 'code':
|
elif tag == 'code':
|
||||||
try:
|
try:
|
||||||
# If we're in the middle of a <pre> tag, this <code> tag is
|
# If we're in the middle of a <pre> tag, this <code> tag is
|
||||||
|
@ -162,6 +169,12 @@ def unparse(text, entities):
|
||||||
html.append('<em>{}</em>'.format(entity_text))
|
html.append('<em>{}</em>'.format(entity_text))
|
||||||
elif entity_type == MessageEntityCode:
|
elif entity_type == MessageEntityCode:
|
||||||
html.append('<code>{}</code>'.format(entity_text))
|
html.append('<code>{}</code>'.format(entity_text))
|
||||||
|
elif entity_type == MessageEntityUnderline:
|
||||||
|
html.append('<u>{}</u>'.format(entity_text))
|
||||||
|
elif entity_type == MessageEntityStrike:
|
||||||
|
html.append('<del>{}</del>'.format(entity_text))
|
||||||
|
elif entity_type == MessageEntityBlockquote:
|
||||||
|
html.append('<blockquote>{}</blockquote>'.format(entity_text))
|
||||||
elif entity_type == MessageEntityPre:
|
elif entity_type == MessageEntityPre:
|
||||||
if entity.language:
|
if entity.language:
|
||||||
html.append(
|
html.append(
|
||||||
|
|
|
@ -9,12 +9,14 @@ from ..helpers import add_surrogate, del_surrogate, strip_text
|
||||||
from ..tl import TLObject
|
from ..tl import TLObject
|
||||||
from ..tl.types import (
|
from ..tl.types import (
|
||||||
MessageEntityBold, MessageEntityItalic, MessageEntityCode,
|
MessageEntityBold, MessageEntityItalic, MessageEntityCode,
|
||||||
MessageEntityPre, MessageEntityTextUrl, MessageEntityMentionName
|
MessageEntityPre, MessageEntityTextUrl, MessageEntityMentionName,
|
||||||
|
MessageEntityStrike
|
||||||
)
|
)
|
||||||
|
|
||||||
DEFAULT_DELIMITERS = {
|
DEFAULT_DELIMITERS = {
|
||||||
'**': MessageEntityBold,
|
'**': MessageEntityBold,
|
||||||
'__': MessageEntityItalic,
|
'__': MessageEntityItalic,
|
||||||
|
'~~': MessageEntityStrike,
|
||||||
'`': MessageEntityCode,
|
'`': MessageEntityCode,
|
||||||
'```': MessageEntityPre
|
'```': MessageEntityPre
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user