##// 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 REFLINK_PATTERN = re.compile(r'^\d+$')
18 REFLINK_PATTERN = re.compile(r'^\d+$')
19 GLOBAL_REFLINK_PATTERN = re.compile(r'(\w+)::([^:]+)::(\d+)')
19 MULTI_NEWLINES_PATTERN = re.compile(r'(\r?\n){2,}')
20 MULTI_NEWLINES_PATTERN = re.compile(r'(\r?\n){2,}')
20 ONE_NEWLINE = '\n'
21 ONE_NEWLINE = '\n'
21 REGEX_URL = re.compile(r'https?\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?')
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 def render_reflink(tag_name, value, options, parent, context):
122 def render_reflink(tag_name, value, options, parent, context):
122 result = '>>%s' % value
123 result = '>>%s' % value
123
124
125 post = None
124 if REFLINK_PATTERN.match(value):
126 if REFLINK_PATTERN.match(value):
125 post_id = int(value)
127 post_id = int(value)
126
128
127 try:
129 try:
128 post = boards.models.Post.objects.get(id=post_id)
130 post = boards.models.Post.objects.get(id=post_id)
129
131
130 result = post.get_link_view()
131 except ObjectDoesNotExist:
132 except ObjectDoesNotExist:
132 pass
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 return result
147 return result
135
148
@@ -177,9 +190,6 b' def render_spoiler(tag_name, value, opti'
177 return '<span class="spoiler">{}{}{}</span>'.format(side_spaces, value,
190 return '<span class="spoiler">{}{}{}</span>'.format(side_spaces, value,
178 side_spaces)
191 side_spaces)
179
192
180 return quote_element
181
182
183
193
184 formatters = [
194 formatters = [
185 QuotePattern,
195 QuotePattern,
General Comments 0
You need to be logged in to leave comments. Login now