mirror of https://gitlab.com/bashrc2/epicyon
Handle single long lines with no spaces
parent
cc99ebf527
commit
29558dabb1
10
content.py
10
content.py
|
@ -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=[]
|
||||||
|
|
3
tests.py
3
tests.py
|
@ -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')
|
||||||
|
|
Loading…
Reference in New Issue