Handle single long lines with no spaces

merge-requests/30/head
Bob Mottram 2019-12-13 12:41:26 +00:00
parent cc99ebf527
commit 29558dabb1
2 changed files with 13 additions and 0 deletions

View File

@ -241,6 +241,16 @@ def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},r
def removeLongWords(content: str,maxWordLength: int,longWordsList: []) -> str: def removeLongWords(content: str,maxWordLength: int,longWordsList: []) -> str:
"""Breaks up long words so that on mobile screens this doesn't disrupt the layout """Breaks up long words so that on mobile screens this doesn't disrupt the layout
""" """
if ' ' not in content:
# handle a single very long string with no spaces
contentStr=content.replace('<p>','').replace('<\p>','')
if '://' not in contentStr:
if len(contentStr)>maxWordLength:
if '<p>' in content:
content='<p>'+contentStr[:maxWordLength]+'<\p>'
else:
content=content[:maxWordLength]
return content
words=content.split(' ') words=content.split(' ')
if not longWordsList: if not longWordsList:
longWordsList=[] longWordsList=[]

View File

@ -1566,6 +1566,9 @@ def testWebLinks():
exampleText='<p>1. HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHHAHAHAHAHAHAHAHAHAHAHAHAHHAHAHAHAHAHAHAHAH</p>' exampleText='<p>1. HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHHAHAHAHAHAHAHAHAHAHAHAHAHHAHAHAHAHAHAHAHAH</p>'
resultText=removeLongWords(exampleText,40,[]) resultText=removeLongWords(exampleText,40,[])
assert resultText=='<p>1. HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA</p>' assert resultText=='<p>1. HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA</p>'
exampleText='<p>ABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABC</p>'
resultText=removeLongWords(exampleText,40,[])
assert resultText=='<p>ABCABCABCABCABCABCABCABCABCABCABCABCABCA<\p>'
def testAddEmoji(): def testAddEmoji():
print('testAddEmoji') print('testAddEmoji')