Advertisement
disk6969

CustomMarkdown + quote

Dec 29th, 2023 (edited)
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. class CustomMarkdown:
  2. @staticmethod
  3. def parse(text):
  4. text, entities = markdown.parse(text)
  5. for i, e in enumerate(entities):
  6. if isinstance(e, types.MessageEntityTextUrl):
  7. if e.url == 'quote':
  8. entities[i] = types.MessageEntityBlockquote(e.offset, e.length)
  9. elif e.url.startswith('emoji/'):
  10. entities[i] = types.MessageEntityCustomEmoji(e.offset, e.length, int(e.url.split('/')[1]))
  11. return text, entities
  12.  
  13. @staticmethod
  14. def unparse(text, entities):
  15. for i, e in enumerate(entities or []):
  16. if isinstance(e, types.MessageEntityCustomEmoji):
  17. entities[i] = types.MessageEntityTextUrl(e.offset, e.length, f'emoji/{e.document_id}')
  18. if isinstance(e, types.MessageEntityBlockquote):
  19. entities[i] = types.MessageEntityTextUrl(e.offset, e.length, 'quote')
  20. return markdown.unparse(text, entities)
  21.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement