forked from indymedia/epicyon
Replace tags with unicode characters
parent
322ba251f4
commit
205ff8b5cb
|
@ -56,8 +56,16 @@ def replaceEmojiFromTags(content: str,tag: [],messageType: str) -> str:
|
||||||
continue
|
continue
|
||||||
if not tagItem['icon'].get('url'):
|
if not tagItem['icon'].get('url'):
|
||||||
continue
|
continue
|
||||||
|
if '/' not in tagItem['icon']['url']:
|
||||||
|
continue
|
||||||
if tagItem['name'] not in content:
|
if tagItem['name'] not in content:
|
||||||
continue
|
continue
|
||||||
|
iconName=tagItem['icon']['url'].split('/')[-1]
|
||||||
|
if iconName:
|
||||||
|
if iconName.startswith('1'):
|
||||||
|
if '.' in iconName:
|
||||||
|
iconName=iconName.split('.')[0]
|
||||||
|
content=content.replace(tagItem['name'],'\\u'+iconName)
|
||||||
htmlClass='emoji'
|
htmlClass='emoji'
|
||||||
if messageType=='post header':
|
if messageType=='post header':
|
||||||
htmlClass='emojiheader'
|
htmlClass='emojiheader'
|
||||||
|
@ -67,6 +75,7 @@ def replaceEmojiFromTags(content: str,tag: [],messageType: str) -> str:
|
||||||
content=content.replace(tagItem['name'],emojiHtml)
|
content=content.replace(tagItem['name'],emojiHtml)
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
def addMusicTag(content: str,tag: str) -> str:
|
def addMusicTag(content: str,tag: str) -> str:
|
||||||
"""If a music link is found then ensure that the post is tagged appropriately
|
"""If a music link is found then ensure that the post is tagged appropriately
|
||||||
"""
|
"""
|
||||||
|
|
4
posts.py
4
posts.py
|
@ -527,15 +527,13 @@ def createPostBase(baseDir: str,nickname: str,domain: str,port: int, \
|
||||||
# convert content to html
|
# convert content to html
|
||||||
emojisDict={}
|
emojisDict={}
|
||||||
|
|
||||||
# replace 's
|
|
||||||
content=content.replace("\ufffd\ufffd\ufffds","'s").replace("’","'")
|
|
||||||
|
|
||||||
# add tags
|
# add tags
|
||||||
content= \
|
content= \
|
||||||
addHtmlTags(baseDir,httpPrefix, \
|
addHtmlTags(baseDir,httpPrefix, \
|
||||||
nickname,domain,content, \
|
nickname,domain,content, \
|
||||||
mentionedRecipients, \
|
mentionedRecipients, \
|
||||||
hashtagsDict,True)
|
hashtagsDict,True)
|
||||||
|
content=replaceEmojiFromTags(content,hashtagsDict,'content')
|
||||||
|
|
||||||
statusNumber,published = getStatusNumber()
|
statusNumber,published = getStatusNumber()
|
||||||
postTo='https://www.w3.org/ns/activitystreams#Public'
|
postTo='https://www.w3.org/ns/activitystreams#Public'
|
||||||
|
|
15
tests.py
15
tests.py
|
@ -1352,8 +1352,9 @@ def testWebLinks():
|
||||||
assert resultText=='<p>ABCABCABCABCABCABCABCABCABCABCABCABCABCA<\p>'
|
assert resultText=='<p>ABCABCABCABCABCABCABCABCABCABCABCABCABCA<\p>'
|
||||||
|
|
||||||
|
|
||||||
def testAddEmoji(content: str,emojiStr:str):
|
def testAddEmoji():
|
||||||
print('testAddEmoji: '+emojiStr)
|
print('testAddEmoji')
|
||||||
|
content="Emoji :lemon: :strawberry: :banana:"
|
||||||
httpPrefix='http'
|
httpPrefix='http'
|
||||||
nickname='testuser'
|
nickname='testuser'
|
||||||
domain='testdomain.net'
|
domain='testdomain.net'
|
||||||
|
@ -1382,17 +1383,15 @@ def testAddEmoji(content: str,emojiStr:str):
|
||||||
addHtmlTags(baseDir,httpPrefix, \
|
addHtmlTags(baseDir,httpPrefix, \
|
||||||
nickname,domain,content, \
|
nickname,domain,content, \
|
||||||
recipients,hashtags,True)
|
recipients,hashtags,True)
|
||||||
assert ':'+emojiStr+':' in contentModified
|
assert ':lemon:' in contentModified
|
||||||
assert contentModified.startswith('<p>')
|
assert contentModified.startswith('<p>')
|
||||||
assert contentModified.endswith('</p>')
|
assert contentModified.endswith('</p>')
|
||||||
tags=[]
|
tags=[]
|
||||||
for tagName,tag in hashtags.items():
|
for tagName,tag in hashtags.items():
|
||||||
tags.append(tag)
|
tags.append(tag)
|
||||||
print(str(tags))
|
|
||||||
content=contentModified
|
content=contentModified
|
||||||
contentModified=replaceEmojiFromTags(content,tags,'content')
|
contentModified=replaceEmojiFromTags(content,tags,'content')
|
||||||
assert 'img src' in contentModified
|
assert contentModified=='<p>Emoji \\u1F34B \\u1F353 \\u1F34C</p>'
|
||||||
assert ':'+emojiStr+':' not in contentModified
|
|
||||||
|
|
||||||
os.chdir(baseDirOriginal)
|
os.chdir(baseDirOriginal)
|
||||||
shutil.rmtree(baseDirOriginal+'/.tests')
|
shutil.rmtree(baseDirOriginal+'/.tests')
|
||||||
|
@ -1474,9 +1473,7 @@ def runAllTests():
|
||||||
testSaveLoadJson()
|
testSaveLoadJson()
|
||||||
testCommentJson()
|
testCommentJson()
|
||||||
testGetStatusNumber()
|
testGetStatusNumber()
|
||||||
testAddEmoji("Emoji :lemon: :strawberry: :banana:","lemon")
|
testAddEmoji()
|
||||||
testAddEmoji("Emoji :lemon: :strawberry: :banana:","banana")
|
|
||||||
testAddEmoji("G'day world :worldmap:","worldmap")
|
|
||||||
testActorParsing()
|
testActorParsing()
|
||||||
testHttpsig()
|
testHttpsig()
|
||||||
testCache()
|
testCache()
|
||||||
|
|
Loading…
Reference in New Issue