mirror of https://gitlab.com/bashrc2/epicyon
Try to remove long words
parent
e6bd4cf1f4
commit
ed2e97ab55
24
content.py
24
content.py
|
@ -240,22 +240,38 @@ def removeLongWords(content: str,maxWordLength: int,longWordsList: []) -> str:
|
|||
"""Breaks up long words so that on mobile screens this doesn't disrupt the layout
|
||||
"""
|
||||
words=content.split(' ')
|
||||
separator='\n'
|
||||
if not longWordsList:
|
||||
longWordsList=[]
|
||||
separator='<br>'
|
||||
for wordStr in words:
|
||||
if len(wordStr)>maxWordLength:
|
||||
if wordStr not in longWordsList:
|
||||
longWordsList.append(wordStr)
|
||||
for wordStr in longWordsList:
|
||||
if wordStr.startswith('<'):
|
||||
continue
|
||||
if wordStr.startswith('http'):
|
||||
if 'https:' in wordStr:
|
||||
continue
|
||||
elif 'http:' in wordStr:
|
||||
continue
|
||||
elif 'dat:' in wordStr:
|
||||
continue
|
||||
suffix=''
|
||||
if '<' in wordStr:
|
||||
suffix='<'+wordStr.split('<',1)[1]
|
||||
wordStr=wordStr.split('<',1)[0]
|
||||
if '/' in wordStr:
|
||||
continue
|
||||
if len(wordStr[maxWordLength:])<maxWordLength:
|
||||
content= \
|
||||
content.replace(wordStr, \
|
||||
wordStr[:maxWordLength]+'\n'+ \
|
||||
wordStr[maxWordLength:])
|
||||
wordStr[:maxWordLength]+separator+ \
|
||||
wordStr[maxWordLength:]+suffix)
|
||||
else:
|
||||
content= \
|
||||
content.replace(wordStr, \
|
||||
wordStr[:maxWordLength])
|
||||
wordStr[:maxWordLength]+suffix)
|
||||
return content
|
||||
|
||||
def addHtmlTags(baseDir: str,httpPrefix: str, \
|
||||
|
|
4
tests.py
4
tests.py
|
@ -69,6 +69,7 @@ from inbox import validInboxFilenames
|
|||
from content import addWebLinks
|
||||
from content import replaceEmojiFromTags
|
||||
from content import addHtmlTags
|
||||
from content import removeLongWords
|
||||
|
||||
testServerAliceRunning = False
|
||||
testServerBobRunning = False
|
||||
|
@ -1528,6 +1529,9 @@ def testWebLinks():
|
|||
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
|
||||
exampleText='<p>1. HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHHAHAHAHAHAHAHAHAHAHAHAHAHHAHAHAHAHAHAHAHAH</p>'
|
||||
resultText=removeLongWords(exampleText,40,[])
|
||||
assert resultText=='<p>1. HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA</p></p>'
|
||||
|
||||
def testAddEmoji():
|
||||
print('testAddEmoji')
|
||||
|
|
|
@ -47,6 +47,7 @@ from blocking import isBlocked
|
|||
from content import getMentionsFromHtml
|
||||
from content import addHtmlTags
|
||||
from content import replaceEmojiFromTags
|
||||
from content import removeLongWords
|
||||
from config import getConfigParam
|
||||
from skills import getSkills
|
||||
from cache import getPersonFromCache
|
||||
|
@ -2205,9 +2206,10 @@ def individualPostAsHtml(iconsDir: str,translate: {}, \
|
|||
postJsonObject['object']['sensitive']=False
|
||||
if not postJsonObject['object'].get('summary'):
|
||||
postJsonObject['object']['summary']=''
|
||||
|
||||
|
||||
objectContent=removeLongWords(postJsonObject['object']['content'],40,[])
|
||||
if not postJsonObject['object']['sensitive']:
|
||||
contentStr=postJsonObject['object']['content']+attachmentStr
|
||||
contentStr=objectContent+attachmentStr
|
||||
contentStr=addEmbeddedElements(translate,contentStr)
|
||||
contentStr=insertQuestion(translate,nickname,contentStr,postJsonObject,pageNumber)
|
||||
else:
|
||||
|
@ -2219,7 +2221,7 @@ def individualPostAsHtml(iconsDir: str,translate: {}, \
|
|||
containerClass='container report'
|
||||
contentStr+='<button class="cwButton" onclick="showContentWarning('+"'"+postID+"'"+')">'+translate['SHOW MORE']+'</button>'
|
||||
contentStr+='<div class="cwText" id="'+postID+'">'
|
||||
contentStr+=postJsonObject['object']['content']+attachmentStr
|
||||
contentStr+=objectContent+attachmentStr
|
||||
contentStr=addEmbeddedElements(translate,contentStr)
|
||||
contentStr=insertQuestion(translate,nickname,contentStr,postJsonObject,pageNumber)
|
||||
contentStr+='</div>'
|
||||
|
|
Loading…
Reference in New Issue