##// END OF EJS Templates
helpers: inline url markup in urlify_text...
Mads Kiilerich -
r6147:ca830f9d default
parent child Browse files
Show More
@@ -1268,16 +1268,12 b' def fancy_file_stats(stats):'
1268 return literal('<div style="width:%spx">%s%s</div>' % (width, d_a, d_d))
1268 return literal('<div style="width:%spx">%s%s</div>' % (width, d_a, d_d))
1269
1269
1270
1270
1271 def _urlify_text_replace(match_obj):
1271 _URLIFY_RE = re.compile(r'''
1272 url_full = match_obj.group(1)
1272 # URL markup
1273 return '<a href="%(url)s">%(url)s</a>' % {'url': url_full}
1273 (?P<url>%s)
1274
1274 ''' % (url_re.pattern),
1275 re.VERBOSE | re.MULTILINE | re.IGNORECASE)
1275
1276
1276 def _urlify_text(s):
1277 """
1278 Extract urls from text and make html links out of them
1279 """
1280 return url_re.sub(_urlify_text_replace, s)
1281
1277
1282
1278
1283 def urlify_text(s, repo_name=None, link_=None, truncate=None, stylize=False, truncatef=truncate):
1279 def urlify_text(s, repo_name=None, link_=None, truncate=None, stylize=False, truncatef=truncate):
@@ -1289,6 +1285,19 b' def urlify_text(s, repo_name=None, link_'
1289 Issues are linked to given issue-server.
1285 Issues are linked to given issue-server.
1290 If link_ is provided, all text not already linking somewhere will link there.
1286 If link_ is provided, all text not already linking somewhere will link there.
1291 """
1287 """
1288
1289 def _replace(match_obj):
1290 url = match_obj.group('url')
1291 if url is not None:
1292 return '<a href="%(url)s">%(url)s</a>' % {'url': url}
1293 return match_obj.group(0)
1294
1295 def _urlify(s):
1296 """
1297 Extract urls from text and make html links out of them
1298 """
1299 return _URLIFY_RE.sub(_replace, s)
1300
1292 if truncate is None:
1301 if truncate is None:
1293 s = s.rstrip()
1302 s = s.rstrip()
1294 else:
1303 else:
@@ -1298,7 +1307,7 b' def urlify_text(s, repo_name=None, link_'
1298 s = urlify_changesets(s, repo_name)
1307 s = urlify_changesets(s, repo_name)
1299 if stylize:
1308 if stylize:
1300 s = desc_stylize(s)
1309 s = desc_stylize(s)
1301 s = _urlify_text(s)
1310 s = _urlify(s)
1302 if repo_name is not None:
1311 if repo_name is not None:
1303 s = urlify_issues(s, repo_name, link_)
1312 s = urlify_issues(s, repo_name, link_)
1304 s = MENTIONS_REGEX.sub(_mentions_replace, s)
1313 s = MENTIONS_REGEX.sub(_mentions_replace, s)
@@ -35,8 +35,9 b' from kallithea.lib.utils2 import safe_un'
35 log = logging.getLogger(__name__)
35 log = logging.getLogger(__name__)
36
36
37
37
38 url_re = re.compile(r'''(\bhttps?://(?:[\da-zA-Z0-9@:.-]+)'''
38 url_re = re.compile(r'''\bhttps?://(?:[\da-zA-Z0-9@:.-]+)'''
39 r'''(?:[/a-zA-Z0-9_=@#~&+%.,:;?!*()-]*[/a-zA-Z0-9_=@#~])?)''')
39 r'''(?:[/a-zA-Z0-9_=@#~&+%.,:;?!*()-]*[/a-zA-Z0-9_=@#~])?''')
40
40
41
41 class MarkupRenderer(object):
42 class MarkupRenderer(object):
42 RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES = ['include', 'meta', 'raw']
43 RESTRUCTUREDTEXT_DISALLOWED_DIRECTIVES = ['include', 'meta', 'raw']
@@ -132,7 +133,7 b' class MarkupRenderer(object):'
132 source = newline.join(source.splitlines())
133 source = newline.join(source.splitlines())
133
134
134 def url_func(match_obj):
135 def url_func(match_obj):
135 url_full = match_obj.groups()[0]
136 url_full = match_obj.group(0)
136 return '<a href="%(url)s">%(url)s</a>' % ({'url': url_full})
137 return '<a href="%(url)s">%(url)s</a>' % ({'url': url_full})
137 source = url_re.sub(url_func, source)
138 source = url_re.sub(url_func, source)
138 return '<br />' + source.replace("\n", '<br />')
139 return '<br />' + source.replace("\n", '<br />')
General Comments 0
You need to be logged in to leave comments. Login now