From 3d9398609c73ed1d0c6a41ad1425944d9ffb201e Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@freedombone.net>
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 7fb04c8a..7b244b54 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+='<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:
diff --git a/tests.py b/tests.py
index 802190fe..8c0f4065 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 '<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')