def format_urls_in_text(text):
new_text = []
accepted_protocols = ['http://', 'https://', 'ftp://', 'ftps://']
for word in str(text).split():
new_word = word
accepted = [protocol for protocol in accepted_protocols if protocol in new_word]
if not accepted:
new_word = 'http://{0}'.format(new_word)
if validators.url(new_word)==True:
new_word = '<a href="{0}">{1}</a>'.format(new_word, word)
else:
new_word = word
new_text.append(new_word)
return ' '.join(new_text)
评论列表
文章目录