Support dat

master
Bob Mottram 2019-11-03 12:37:47 +00:00
parent 8d78bb6f6b
commit a6dc579aca
1 changed files with 5 additions and 3 deletions

View File

@ -30,13 +30,13 @@ def addMusicTag(content: str,tag: str) -> str:
def addWebLinks(content: str) -> str: def addWebLinks(content: str) -> str:
"""Adds markup for web links """Adds markup for web links
""" """
if not ('https://' in content or 'http://' in content): if not ('https://' in content or 'http://' in content or 'dat://' in content):
return content return content
words=content.replace('\n',' --linebreak--').split(' ') words=content.replace('\n',' --linebreak--').split(' ')
replaceDict={} replaceDict={}
for w in words: for w in words:
if w.startswith('https://') or w.startswith('http://'): if w.startswith('https://') or w.startswith('http://') or w.startswith('dat://'):
if w.endswith('.') or w.endswith(';'): if w.endswith('.') or w.endswith(';'):
w=w[:-1] w=w[:-1]
markup='<a href="'+w+'" rel="nofollow noopener" target="_blank">' markup='<a href="'+w+'" rel="nofollow noopener" target="_blank">'
@ -44,7 +44,9 @@ def addWebLinks(content: str) -> str:
markup+='<span class="invisible">https://</span>' markup+='<span class="invisible">https://</span>'
elif w.startswith('http://'): elif w.startswith('http://'):
markup+='<span class="invisible">http://</span>' markup+='<span class="invisible">http://</span>'
markup+='<span class="ellipsis">'+w.replace('https://','').replace('http://','')+'</span></a>' elif w.startswith('dat://'):
markup+='<span class="invisible">dat://</span>'
markup+='<span class="ellipsis">'+w.replace('https://','').replace('http://','').replace('dat://','')+'</span></a>'
replaceDict[w]=markup replaceDict[w]=markup
for url,markup in replaceDict.items(): for url,markup in replaceDict.items():
content=content.replace(url,markup) content=content.replace(url,markup)