Handle newlines when adding links

master
Bob Mottram 2019-09-01 09:55:05 +01:00
parent cbfa590727
commit 565bf041e2
2 changed files with 10 additions and 1 deletions

View File

@ -16,7 +16,7 @@ def addWebLinks(content: str) -> str:
if not ('https://' in content or 'http://' in content): if not ('https://' in content or 'http://' in content):
return content return content
words=content.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://'):
@ -31,6 +31,7 @@ def addWebLinks(content: str) -> str:
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)
content=content.replace(' --linebreak--','<br>')
return content return content
def validHashTag(hashtag: str) -> bool: def validHashTag(hashtag: str) -> bool:

View File

@ -64,6 +64,7 @@ from media import getAttachmentMediaType
from delete import sendDeleteViaServer from delete import sendDeleteViaServer
from inbox import validInbox from inbox import validInbox
from inbox import validInboxFilenames from inbox import validInboxFilenames
from content import addWebLinks
testServerAliceRunning = False testServerAliceRunning = False
testServerBobRunning = False testServerBobRunning = False
@ -1368,8 +1369,15 @@ def testActorParsing():
nickname=getNicknameFromActor(actor) nickname=getNicknameFromActor(actor)
assert nickname=='othernick' 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(): def runAllTests():
print('Running tests...') print('Running tests...')
testWebLinks()
testActorParsing() testActorParsing()
testHttpsig() testHttpsig()
testCache() testCache()