From 40f85c162bad8ba1648c10dce67a41094d82035f Mon Sep 17 00:00:00 2001 From: EyeZiS Date: Wed, 9 May 2018 00:50:20 +0200 Subject: [PATCH] parse text snippets --- stdplugins/markdown.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/stdplugins/markdown.py b/stdplugins/markdown.py index 87cc192..b4da567 100644 --- a/stdplugins/markdown.py +++ b/stdplugins/markdown.py @@ -42,13 +42,25 @@ def parse_subreddit(m): return m.group(1) + text, entity +def parse_snip(m): + try: + name = m.group(1)[1:] + snip = borg._plugins['snip'].storage.snips[name] + if snip['type'] == borg._plugins['snip'].TYPE_TEXT: + return snip['text'], None + except KeyError: + pass + return m.group(1), None + + 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)), - (re.compile(r'([^/\w]|^)(/?(r/\w+))'), parse_subreddit) + (re.compile(r'([^/\w]|^)(/?(r/\w+))'), parse_subreddit), + (re.compile(r'(!\S+)'), parse_snip) ]