Replace tags with unicode characters

main
Bob Mottram 2020-02-21 15:09:31 +00:00
parent 322ba251f4
commit 205ff8b5cb
3 changed files with 16 additions and 12 deletions

View File

@ -56,8 +56,16 @@ def replaceEmojiFromTags(content: str,tag: [],messageType: str) -> str:
continue
if not tagItem['icon'].get('url'):
continue
if '/' not in tagItem['icon']['url']:
continue
if tagItem['name'] not in content:
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'
if messageType=='post header':
htmlClass='emojiheader'
@ -67,6 +75,7 @@ def replaceEmojiFromTags(content: str,tag: [],messageType: str) -> str:
content=content.replace(tagItem['name'],emojiHtml)
return content
def addMusicTag(content: str,tag: str) -> str:
"""If a music link is found then ensure that the post is tagged appropriately
"""

View File

@ -527,15 +527,13 @@ def createPostBase(baseDir: str,nickname: str,domain: str,port: int, \
# convert content to html
emojisDict={}
# replace 's
content=content.replace("\ufffd\ufffd\ufffds","'s").replace("","'")
# add tags
content= \
addHtmlTags(baseDir,httpPrefix, \
nickname,domain,content, \
mentionedRecipients, \
hashtagsDict,True)
content=replaceEmojiFromTags(content,hashtagsDict,'content')
statusNumber,published = getStatusNumber()
postTo='https://www.w3.org/ns/activitystreams#Public'

View File

@ -1352,8 +1352,9 @@ def testWebLinks():
assert resultText=='<p>ABCABCABCABCABCABCABCABCABCABCABCABCABCA<\p>'
def testAddEmoji(content: str,emojiStr:str):
print('testAddEmoji: '+emojiStr)
def testAddEmoji():
print('testAddEmoji')
content="Emoji :lemon: :strawberry: :banana:"
httpPrefix='http'
nickname='testuser'
domain='testdomain.net'
@ -1382,17 +1383,15 @@ def testAddEmoji(content: str,emojiStr:str):
addHtmlTags(baseDir,httpPrefix, \
nickname,domain,content, \
recipients,hashtags,True)
assert ':'+emojiStr+':' in contentModified
assert ':lemon:' in contentModified
assert contentModified.startswith('<p>')
assert contentModified.endswith('</p>')
tags=[]
for tagName,tag in hashtags.items():
tags.append(tag)
print(str(tags))
content=contentModified
contentModified=replaceEmojiFromTags(content,tags,'content')
assert 'img src' in contentModified
assert ':'+emojiStr+':' not in contentModified
assert contentModified=='<p>Emoji \\u1F34B \\u1F353 \\u1F34C</p>'
os.chdir(baseDirOriginal)
shutil.rmtree(baseDirOriginal+'/.tests')
@ -1474,9 +1473,7 @@ def runAllTests():
testSaveLoadJson()
testCommentJson()
testGetStatusNumber()
testAddEmoji("Emoji :lemon: :strawberry: :banana:","lemon")
testAddEmoji("Emoji :lemon: :strawberry: :banana:","banana")
testAddEmoji("G'day world :worldmap:","worldmap")
testAddEmoji()
testActorParsing()
testHttpsig()
testCache()