From cb49d90bb90f5f1eb6fb6a70832e3788a16b77bd Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Sat, 31 Oct 2020 23:10:38 +0000
Subject: [PATCH] Removing long words from feed titles
---
content.py | 2 +-
newswire.py | 5 -----
tests.py | 9 +++++++++
webinterface.py | 8 +++++---
4 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/content.py b/content.py
index f406ac7af..95181a865 100644
--- a/content.py
+++ b/content.py
@@ -639,7 +639,7 @@ def removeLongWords(content: str, maxWordLength: int,
wordStr[:maxWordLength])
if content.startswith(''):
if not content.endswith('
'):
- content = content.strip()+'
'
+ content = content.strip() + ''
return content
diff --git a/newswire.py b/newswire.py
index 462ea5703..cc2eb538e 100644
--- a/newswire.py
+++ b/newswire.py
@@ -22,7 +22,6 @@ from utils import removeHtml
from blocking import isBlockedDomain
from blocking import isBlockedHashtag
from filters import isFiltered
-from content import removeLongWords
def rss2Header(httpPrefix: str,
@@ -90,10 +89,6 @@ def addNewswireDictEntry(baseDir: str, domain: str,
tags=[], maxTags=32) -> None:
"""Update the newswire dictionary
"""
- # remove any long words from the title, which can
- # cause column overflows
- title = removeLongWords(title, 30, [])
-
allText = removeHtml(title + ' ' + description)
# check that none of the text is filtered against
diff --git a/tests.py b/tests.py
index bd497241d..647a8376a 100644
--- a/tests.py
+++ b/tests.py
@@ -1674,6 +1674,15 @@ def testWebLinks():
resultText = removeLongWords(exampleText, 40, [])
assert resultText == exampleText
+ exampleText = \
+ 'some.incredibly.long.and.annoying.word.which.should.be.removed: ' + \
+ 'The remaining text'
+ resultText = removeLongWords(exampleText, 40, [])
+ print('resultText: ' + resultText)
+ assert resultText == \
+ 'some.incredibly.long.and.annoying.word.w\n' + \
+ 'hich.should.be.removed: The remaining text'
+
exampleText = \
'Tox address is 88AB9DED6F9FBEF43E105FB72060A2D89F9B93C74' + \
'4E8C45AB3C5E42C361C837155AFCFD9D448
'
diff --git a/webinterface.py b/webinterface.py
index 694eec974..1f6bd4ad5 100644
--- a/webinterface.py
+++ b/webinterface.py
@@ -5707,9 +5707,10 @@ def htmlNewswire(newswire: {}, nickname: str, moderator: bool,
totalVotesStr = \
votesIndicator(totalVotes, positiveVoting)
+ title = removeLongWords(item[0], 30, []).replace('\n', '
')
htmlStr += '' + \
'' + \
- '' + item[0] + \
+ '' + title + \
'' + totalVotesStr
if moderator:
htmlStr += \
@@ -5732,10 +5733,11 @@ def htmlNewswire(newswire: {}, nickname: str, moderator: bool,
totalVotesStr = \
votesIndicator(totalVotes, positiveVoting)
+ title = removeLongWords(item[0], 30, []).replace('\n', '
')
if moderator and moderatedItem:
htmlStr += '
' + \
'' + \
- item[0] + '' + totalVotesStr
+ title + '' + totalVotesStr
htmlStr += ' ' + dateShown
htmlStr += '' + \
'' + \
- item[0] + '' + \
+ title + '' + \
totalVotesStr
htmlStr += ' '
htmlStr += dateShown + '
\n'