From 1b15e9ff431016eb20d23aae2b2e937cbc639cdb Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 29 Sep 2019 18:20:10 +0100 Subject: [PATCH] Separate tag replacement functions --- content.py | 33 +++++++++++++++++++++++++++------ posts.py | 4 ++-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/content.py b/content.py index 47500bd63..305eef5e2 100644 --- a/content.py +++ b/content.py @@ -11,14 +11,35 @@ import time import commentjson from shutil import copyfile -def replaceEmojiFromTags(content: str,tag,messageType: str) -> str: +def replaceEmojiFromTags(content: str,tag: [],messageType: str) -> str: """Uses the tags to replace :emoji: with html image markup """ - tagList=tag - if isinstance(tag, dict): - tagList=tag.items() - - for tagItem in tagList: + for tagItem in tag: + if not tagItem.get('type'): + continue + if tagItem['type']!='Emoji': + continue + if not tagItem.get('name'): + continue + if not tagItem.get('icon'): + continue + if not tagItem['icon'].get('url'): + continue + if tagItem['name'] not in content: + continue + htmlClass='emoji' + if messageType=='post header': + htmlClass='emojiheader' + if messageType=='profile': + htmlClass='emojiprofile' + emojiHtml="\""+tagItem['name'].replace(':','')+"\"" + content=content.replace(tagItem['name'],emojiHtml) + return content + +def replaceEmojiFromTagsDict(content: str,tag: {},messageType: str) -> str: + """Uses the tags dictionary to replace :emoji: with html image markup + """ + for tagName,tagItem in tag.items(): if not tagItem.get('type'): continue if tagItem['type']!='Emoji': diff --git a/posts.py b/posts.py index 7811ec244..71402658a 100644 --- a/posts.py +++ b/posts.py @@ -41,7 +41,7 @@ from capabilities import getOcapFilename from capabilities import capabilitiesUpdate from media import attachMedia from content import addHtmlTags -from content import replaceEmojiFromTags +from content import replaceEmojiFromTagsDict from auth import createBasicAuthHeader from config import getConfigParam from blocking import isBlocked @@ -460,7 +460,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \ nickname,domain,content, \ mentionedRecipients, \ hashtagsDict) - content=replaceEmojiFromTags(content,hashtagsDict,'content') + content=replaceEmojiFromTagsDict(content,hashtagsDict,'content') statusNumber,published = getStatusNumber() postTo='https://www.w3.org/ns/activitystreams#Public'