# HG changeset patch # User neko259 # Date 2016-05-08 11:16:52 # Node ID 4c509fcc26457052b20c68b8dd01636f457c7a0b # Parent 936c0c67ccf5294e47a5b0c185514c094b9686aa Parse global reflinks diff --git a/boards/mdx_neboard.py b/boards/mdx_neboard.py --- a/boards/mdx_neboard.py +++ b/boards/mdx_neboard.py @@ -16,6 +16,7 @@ import boards REFLINK_PATTERN = re.compile(r'^\d+$') +GLOBAL_REFLINK_PATTERN = re.compile(r'(\w+)::([^:]+)::(\d+)') MULTI_NEWLINES_PATTERN = re.compile(r'(\r?\n){2,}') ONE_NEWLINE = '\n' REGEX_URL = re.compile(r'https?\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?') @@ -121,15 +122,27 @@ class CodePattern(TextFormatter): def render_reflink(tag_name, value, options, parent, context): result = '>>%s' % value + post = None if REFLINK_PATTERN.match(value): post_id = int(value) try: post = boards.models.Post.objects.get(id=post_id) - result = post.get_link_view() except ObjectDoesNotExist: pass + elif GLOBAL_REFLINK_PATTERN.match(value): + match = GLOBAL_REFLINK_PATTERN.search(value) + try: + global_id = boards.models.GlobalId.objects.get( + key_type=match.group(1), key=match.group(2), + local_id=match.group(3)) + post = global_id.post + except ObjectDoesNotExist: + pass + + if post is not None: + result = post.get_link_view() return result @@ -177,9 +190,6 @@ def render_spoiler(tag_name, value, opti return '{}{}{}'.format(side_spaces, value, side_spaces) - return quote_element - - formatters = [ QuotePattern,