Handle newlines when adding links

This commit is contained in:
bashrc committed 2019-09-01 09:55:05 +01:00
1 parent cbfa590727
commit 565bf041e2
2 files changed
+10 -1

No files matched your search

+2 -1
View File
@@ -16,7 +16,7 @@ def addWebLinks(content: str) -> str:
if not ('https://' in content or 'http://' in content):
return content
words=content.split(' ')
words=content.replace('\n',' --linebreak--').split(' ')
replaceDict={}
for w in words:
if w.startswith('https://') or w.startswith('http://'):
@@ -31,6 +31,7 @@ def addWebLinks(content: str) -> str:
replaceDict[w]=markup
for url,markup in replaceDict.items():
content=content.replace(url,markup)
content=content.replace(' --linebreak--','<br>')
return content
def validHashTag(hashtag: str) -> bool:
+8
View File
@@ -64,6 +64,7 @@ from media import getAttachmentMediaType
from delete import sendDeleteViaServer
from inbox import validInbox
from inbox import validInboxFilenames
from content import addWebLinks
testServerAliceRunning = False
testServerBobRunning = False
@@ -1368,8 +1369,15 @@ def testActorParsing():
nickname=getNicknameFromActor(actor)
assert nickname=='othernick'
def testWebLinks():
exampleText='This post has a web links https://somesite.net\n\nAnd some other text'
linkedText=addWebLinks(exampleText)
print(exampleText)
print(linkedText)
def runAllTests():
print('Running tests...')
testWebLinks()
testActorParsing()
testHttpsig()
testCache()