mirror of https://gitlab.com/bashrc2/epicyon
Handle newlines when adding links
parent
cbfa590727
commit
565bf041e2
|
@ -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
tests.py
8
tests.py
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue