mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 00:26:33 +00:00
Improves link detecting regex
This commit is contained in:
parent
a25bc2383b
commit
9e07f094ad
2 changed files with 15 additions and 1 deletions
|
@ -294,8 +294,9 @@ def find_mentions(content):
|
||||||
|
|
||||||
|
|
||||||
def format_links(content):
|
def format_links(content):
|
||||||
|
''' detect and format links '''
|
||||||
return re.sub(
|
return re.sub(
|
||||||
r'([^(href=")]|^)(https?:\/\/([\w\.\-_]+\.[a-z]{2,}(\/[\w\.\-_\/]+)?))',
|
r'([^(href=")]|^)(https?:\/\/(%s([\w\.\-_\/])*))' % regex.domain,
|
||||||
r'\g<1><a href="\g<2>">\g<3></a>',
|
r'\g<1><a href="\g<2>">\g<3></a>',
|
||||||
content)
|
content)
|
||||||
|
|
||||||
|
|
|
@ -490,3 +490,16 @@ class Outgoing(TestCase):
|
||||||
list(outgoing.find_mentions('@nutria@%s' % DOMAIN))[0],
|
list(outgoing.find_mentions('@nutria@%s' % DOMAIN))[0],
|
||||||
('@nutria@%s' % DOMAIN, user)
|
('@nutria@%s' % DOMAIN, user)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_format_links(self):
|
||||||
|
''' find and format urls into a tags '''
|
||||||
|
url = 'http://www.fish.com/'
|
||||||
|
self.assertEqual(
|
||||||
|
outgoing.format_links(url),
|
||||||
|
'<a href="%s">www.fish.com/</a>' % url)
|
||||||
|
url = 'https://archive.org/details/dli.granth.72113/page/n25/mode/2up'
|
||||||
|
self.assertEqual(
|
||||||
|
outgoing.format_links(url),
|
||||||
|
'<a href="%s">' \
|
||||||
|
'archive.org/details/dli.granth.72113/page/n25/mode/2up</a>' \
|
||||||
|
% url)
|
||||||
|
|
Loading…
Reference in a new issue