未知
autolink_p的Python项目详细描述
回购协议从给定字符串中提取url/email子字符串并将其转换为 链接(或任何自定义格式)。 类型,也适用于简单的方式定制更换。
安装
使用pip:
安装pip install autolink_py
用法
- 用HTML格式替换URL
fromautolink_py.coreimportAutoLinkertext='This website is google.com'al=AutoLinker()new_text=al.linkify(text,replaced_type='HTML')# new_text -> 'This website is <a href="http://google.com">google.com</a>'
- 将URL替换为降价格式
fromautolink_py.coreimportAutoLinkertext='This website is google.com'al=AutoLinker()new_text=al.linkify(text,replaced_type='MARKDOWN')# new_text -> 'This website is [google.com](http://google.com)'
- 用自定义格式替换URL
# example: 'google.com' -> '<google.com><http://google.com>'fromautolink_py.coreimportAutoLinkerclassNewAutoLinker(AutoLinker):defreplace_url(self,text,url):''' implement replace_url to customize the format you need. Params: text: url text that shown originally url: newly generated link including complete protocal based on text. '''returnu'<{0}><{1}>'.format(text,url)text='The website is google.com'nal=NewAutoLinker()new_text=nal.linkify(text)# new_text -> 'The website is <google.com><http://google.com>'
学分
核心算法由开源repo引用:autolink