forked from indymedia/epicyon
Tidying
parent
34140b6ee9
commit
5a002e7d5e
35
content.py
35
content.py
|
@ -100,10 +100,6 @@ def addHashTags(wordStr: str,httpPrefix: str,domain: str,replaceHashTags: {},pos
|
||||||
"""Detects hashtags and adds them to the replacements dict
|
"""Detects hashtags and adds them to the replacements dict
|
||||||
Also updates the hashtags list to be added to the post
|
Also updates the hashtags list to be added to the post
|
||||||
"""
|
"""
|
||||||
if not wordStr.startswith('#'):
|
|
||||||
return False
|
|
||||||
if len(wordStr)<2:
|
|
||||||
return False
|
|
||||||
if replaceHashTags.get(wordStr):
|
if replaceHashTags.get(wordStr):
|
||||||
return True
|
return True
|
||||||
hashtag=wordStr[1:]
|
hashtag=wordStr[1:]
|
||||||
|
@ -182,10 +178,6 @@ def addEmoji(baseDir: str,wordStr: str,httpPrefix: str,domain: str,replaceEmoji:
|
||||||
def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},recipients: [],tags: {}) -> bool:
|
def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},recipients: [],tags: {}) -> bool:
|
||||||
"""Detects mentions and adds them to the replacements dict and recipients list
|
"""Detects mentions and adds them to the replacements dict and recipients list
|
||||||
"""
|
"""
|
||||||
if not wordStr.startswith('@'):
|
|
||||||
return False
|
|
||||||
if len(wordStr)<2:
|
|
||||||
return False
|
|
||||||
possibleHandle=wordStr[1:]
|
possibleHandle=wordStr[1:]
|
||||||
# @nick
|
# @nick
|
||||||
if following and '@' not in possibleHandle:
|
if following and '@' not in possibleHandle:
|
||||||
|
@ -238,13 +230,13 @@ def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},r
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def removeLongWords(content: str,maxWordLength: int) -> 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
|
||||||
"""
|
"""
|
||||||
words=content.split(' ')
|
words=content.split(' ')
|
||||||
for wordStr in words:
|
for wordStr in longWordsList:
|
||||||
if not wordStr.startswith('<'):
|
if wordStr.startswith('<'):
|
||||||
if len(wordStr)>maxWordLength:
|
continue
|
||||||
if len(wordStr[maxWordLength:])<maxWordLength:
|
if len(wordStr[maxWordLength:])<maxWordLength:
|
||||||
content= \
|
content= \
|
||||||
content.replace(wordStr, \
|
content.replace(wordStr, \
|
||||||
|
@ -294,21 +286,26 @@ def addHtmlTags(baseDir: str,httpPrefix: str, \
|
||||||
# read the following list so that we can detect just @nick
|
# read the following list so that we can detect just @nick
|
||||||
# in addition to @nick@domain
|
# in addition to @nick@domain
|
||||||
following=None
|
following=None
|
||||||
|
if '@' in words:
|
||||||
if os.path.isfile(followingFilename):
|
if os.path.isfile(followingFilename):
|
||||||
with open(followingFilename, "r") as f:
|
with open(followingFilename, "r") as f:
|
||||||
following = f.readlines()
|
following = f.readlines()
|
||||||
|
|
||||||
# extract mentions and tags from words
|
# extract mentions and tags from words
|
||||||
longWordsExist=False
|
longWordsList=[]
|
||||||
for wordStr in words:
|
for wordStr in words:
|
||||||
if len(wordStr)>maxWordLength:
|
wordLen=len(wordStr)
|
||||||
longWordsExist=True
|
if wordLen>2:
|
||||||
|
if wordLen>maxWordLength:
|
||||||
|
longWordsList.append(wordStr)
|
||||||
|
firstChar=wordStr[0]
|
||||||
|
if firstChar=='@':
|
||||||
if addMention(wordStr,httpPrefix,following,replaceMentions,recipients,hashtags):
|
if addMention(wordStr,httpPrefix,following,replaceMentions,recipients,hashtags):
|
||||||
continue
|
continue
|
||||||
|
elif firstChar=='#':
|
||||||
if addHashTags(wordStr,httpPrefix,originalDomain,replaceHashTags,hashtags):
|
if addHashTags(wordStr,httpPrefix,originalDomain,replaceHashTags,hashtags):
|
||||||
continue
|
continue
|
||||||
if len(wordStr)>2:
|
elif ':' in wordStr:
|
||||||
if ':' in wordStr:
|
|
||||||
#print('TAG: emoji located - '+wordStr)
|
#print('TAG: emoji located - '+wordStr)
|
||||||
wordStr2=wordStr.split(':')[1]
|
wordStr2=wordStr.split(':')[1]
|
||||||
if not emojiDict:
|
if not emojiDict:
|
||||||
|
@ -343,8 +340,8 @@ def addHtmlTags(baseDir: str,httpPrefix: str, \
|
||||||
content=content.replace(wordStr,replaceStr)
|
content=content.replace(wordStr,replaceStr)
|
||||||
|
|
||||||
content=addWebLinks(content)
|
content=addWebLinks(content)
|
||||||
if longWordsExist:
|
if longWordsList:
|
||||||
content=removeLongWords(content,maxWordLength)
|
content=removeLongWords(content,maxWordLength,longWordsList)
|
||||||
content=content.replace(' --linebreak-- ','</p><p>')
|
content=content.replace(' --linebreak-- ','</p><p>')
|
||||||
return '<p>'+content+'</p>'
|
return '<p>'+content+'</p>'
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue