##// END OF EJS Templates
Parse global reflinks
neko259 -
r1528:4c509fcc decentral
parent child Browse files
Show More
@@ -16,6 +16,7 b' import boards'
16 16
17 17
18 18 REFLINK_PATTERN = re.compile(r'^\d+$')
19 GLOBAL_REFLINK_PATTERN = re.compile(r'(\w+)::([^:]+)::(\d+)')
19 20 MULTI_NEWLINES_PATTERN = re.compile(r'(\r?\n){2,}')
20 21 ONE_NEWLINE = '\n'
21 22 REGEX_URL = re.compile(r'https?\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?')
@@ -121,15 +122,27 b' class CodePattern(TextFormatter):'
121 122 def render_reflink(tag_name, value, options, parent, context):
122 123 result = '>>%s' % value
123 124
125 post = None
124 126 if REFLINK_PATTERN.match(value):
125 127 post_id = int(value)
126 128
127 129 try:
128 130 post = boards.models.Post.objects.get(id=post_id)
129 131
130 result = post.get_link_view()
131 132 except ObjectDoesNotExist:
132 133 pass
134 elif GLOBAL_REFLINK_PATTERN.match(value):
135 match = GLOBAL_REFLINK_PATTERN.search(value)
136 try:
137 global_id = boards.models.GlobalId.objects.get(
138 key_type=match.group(1), key=match.group(2),
139 local_id=match.group(3))
140 post = global_id.post
141 except ObjectDoesNotExist:
142 pass
143
144 if post is not None:
145 result = post.get_link_view()
133 146
134 147 return result
135 148
@@ -177,9 +190,6 b' def render_spoiler(tag_name, value, opti'
177 190 return '<span class="spoiler">{}{}{}</span>'.format(side_spaces, value,
178 191 side_spaces)
179 192
180 return quote_element
181
182
183 193
184 194 formatters = [
185 195 QuotePattern,
General Comments 0
You need to be logged in to leave comments. Login now