Compare commits

..

4 commits

Author SHA1 Message Date
wulan17
2de6d80905
pyrofork: Add support for custom emoji in markdown unparser
Some checks failed
Build-docs / build (push) Has been cancelled
Pyrofork / build (macos-latest, 3.10) (push) Has been cancelled
Pyrofork / build (macos-latest, 3.11) (push) Has been cancelled
Pyrofork / build (macos-latest, 3.12) (push) Has been cancelled
Pyrofork / build (macos-latest, 3.13) (push) Has been cancelled
Pyrofork / build (macos-latest, 3.9) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.10) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.11) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.12) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.13) (push) Has been cancelled
Pyrofork / build (ubuntu-latest, 3.9) (push) Has been cancelled
Signed-off-by: wulan17 <wulan17@nusantararom.org>
2025-03-03 05:17:06 +07:00
wulan17
e58354c98a
pyrofork: Add offset_{date,id,topic} parameters to get_forum_topics method
Signed-off-by: wulan17 <wulan17@nusantararom.org>
2025-03-03 05:17:06 +07:00
wulan17
a556504770
pyrofork: Add support for multi-line blockquote in markdown unparser
Signed-off-by: wulan17 <wulan17@nusantararom.org>
2025-03-03 05:17:05 +07:00
wulan17
9105c1a9f3
pyrofork: Adapt markdown unparser from telethon
* The problem with current implementation is when we have nested markdown inside a url the markdown order is messed up.
for example link with bold text will be unparsed like this [**github](https://github.com**).

Signed-off-by: wulan17 <wulan17@nusantararom.org>
2025-03-03 05:16:37 +07:00

View file

@ -214,10 +214,11 @@ class Markdown:
open_delimiter = delimiter
close_delimiter = delimiter
if entity.type == MessageEntityType.PRE:
close_delimiter = '\n' + delimiter
if entity.language:
open_delimiter += entity.language + '\n'
else:
open_delimiter += entity + '\n'
open_delimiter += '\n'
insert_at.append((s, i, open_delimiter))
insert_at.append((e, -i, close_delimiter))
else:
@ -233,13 +234,20 @@ class Markdown:
# No closing delimiter for blockquotes
else:
url = None
is_emoji = False
if entity.type == MessageEntityType.TEXT_LINK:
url = entity.url
elif entity.type == MessageEntityType.TEXT_MENTION:
url = 'tg://user?id={}'.format(entity.user.id)
url = f'tg://user?id={entity.user.id}'
elif entity.type == MessageEntityType.CUSTOM_EMOJI:
url = f"tg://emoji?id={entity.custom_emoji_id}"
is_emoji = True
if url:
insert_at.append((s, i, '['))
insert_at.append((e, -i, ']({})'.format(url)))
if is_emoji:
insert_at.append((s, i, '!['))
else:
insert_at.append((s, i, '['))
insert_at.append((e, -i, f']({url})'))
insert_at.sort(key=lambda t: (t[0], t[1]))
while insert_at: