From 3d9398609c73ed1d0c6a41ad1425944d9ffb201e Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 1 Oct 2019 11:36:51 +0100 Subject: [PATCH] Linebreaks with extra space --- content.py | 9 +++++---- tests.py | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/content.py b/content.py index 7fb04c8a5..7b244b541 100644 --- a/content.py +++ b/content.py @@ -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+='' 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+=''+linkText+'' replaceDict[w]=markup for url,markup in replaceDict.items(): content=content.replace(url,markup) - content=content.replace(' --linebreak--','
') + content=content.replace(' --linebreak-- ','
') return content def validHashTag(hashtag: str) -> bool: diff --git a/tests.py b/tests.py index 802190fef..8c0f40656 100644 --- a/tests.py +++ b/tests.py @@ -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 'somesite.net