From 969da5bcc99d3968343c5aa4e68e5a26c0ccb597 Mon Sep 17 00:00:00 2001 From: EyeZiS Date: Tue, 8 May 2018 23:53:00 +0200 Subject: [PATCH] parse /r/subreddit links --- stdplugins/markdown.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/stdplugins/markdown.py b/stdplugins/markdown.py index 9e793b9..91edcda 100644 --- a/stdplugins/markdown.py +++ b/stdplugins/markdown.py @@ -32,12 +32,23 @@ def get_tag_parser(tag, entity): return re.compile(tag + r'(.+?)' + tag, re.DOTALL), tag_parser +def parse_subreddit(m): + text = '/' + m.group(3) + entity = MessageEntityTextUrl( + offset=m.start(2), + length=len(text), + url=f'reddit.com{text}' + ) + return m.group(1) + text, entity + + MATCHERS = [ (DEFAULT_URL_RE, parse_url_match), (get_tag_parser('**', MessageEntityBold)), (get_tag_parser('__', MessageEntityItalic)), (get_tag_parser('```', partial(MessageEntityPre, language=''))), - (get_tag_parser('`', MessageEntityCode)) + (get_tag_parser('`', MessageEntityCode)), + (re.compile(r'([^/\w]|^)(/?(r/\w+))'), parse_subreddit) ]