__init__.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:emile-server 作者: gsort 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号