Linebreaks with extra space

main2
Bob Mottram 2019-10-01 11:36:51 +01:00
parent 708f1d8a2a
commit 3d9398609c
2 changed files with 8 additions and 4 deletions

View File

@ -59,7 +59,8 @@ def addWebLinks(content: str) -> str:
if not ('https://' in content or 'http://' in content):
return content
words=content.replace('\n',' --linebreak--').split(' ')
words=content.replace('\n',' --linebreak-- ').split(' ')
print(str(words))
replaceDict={}
for w in words:
if w.startswith('https://') or \
@ -76,13 +77,13 @@ def addWebLinks(content: str) -> str:
markup+='<span class="invisible">dat://</span>'
linkText=w.replace('https://','').replace('http://','').replace('dat://','')
# prevent links from becoming too long
if len(linkText)>50:
linkText=linkText[:50]
if len(linkText)>40:
linkText=linkText[:40]
markup+='<span class="ellipsis">'+linkText+'</span></a>'
replaceDict[w]=markup
for url,markup in replaceDict.items():
content=content.replace(url,markup)
content=content.replace(' --linebreak--','<br>')
content=content.replace(' --linebreak-- ','<br>')
return content
def validHashTag(hashtag: str) -> bool:

View File

@ -1381,6 +1381,9 @@ def testWebLinks():
exampleText='This post has a web links https://somesite.net\n\nAnd some other text'
linkedText=addWebLinks(exampleText)
assert '<a href="https://somesite.net" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">somesite.net</span></a' in linkedText
exampleText='This post has a very long web link\n\nhttp://cbwebewuvfuftdiudbqd33dddbbyuef23fyug3bfhcyu2fct2cuyqbcbucuwvckiwyfgewfvqejbchevbhwevuevwbqebqekveqvuvjfkf.onion\n\nAnd some other text'
linkedText=addWebLinks(exampleText)
assert 'ellipsis' in linkedText
def testAddEmoji():
print('testAddEmoji')