parse text snippets

This commit is contained in:
EyeZiS 2018-05-09 00:50:20 +02:00
parent edd042190d
commit 40f85c162b
Signed by untrusted user: kate
GPG Key ID: F17AECB58C3A3096
1 changed files with 13 additions and 1 deletions

View File

@ -42,13 +42,25 @@ def parse_subreddit(m):
return m.group(1) + text, entity 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 = [ MATCHERS = [
(DEFAULT_URL_RE, parse_url_match), (DEFAULT_URL_RE, parse_url_match),
(get_tag_parser('**', MessageEntityBold)), (get_tag_parser('**', MessageEntityBold)),
(get_tag_parser('__', MessageEntityItalic)), (get_tag_parser('__', MessageEntityItalic)),
(get_tag_parser('```', partial(MessageEntityPre, language=''))), (get_tag_parser('```', partial(MessageEntityPre, language=''))),
(get_tag_parser('`', MessageEntityCode)), (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)
] ]