mirror of https://gitlab.com/bashrc2/epicyon
Don't speak emoji eithin display names
parent
f052cabca5
commit
bcedcd3f06
2
blog.py
2
blog.py
|
@ -284,7 +284,7 @@ def _html_blog_post_content(debug: bool, session, authorized: bool,
|
||||||
content_str = replace_emoji_from_tags(session, base_dir,
|
content_str = replace_emoji_from_tags(session, base_dir,
|
||||||
content_str,
|
content_str,
|
||||||
post_json_object_tags,
|
post_json_object_tags,
|
||||||
'content', debug)
|
'content', debug, True)
|
||||||
if article_added:
|
if article_added:
|
||||||
blog_str += '<br>' + content_str + '</article>\n'
|
blog_str += '<br>' + content_str + '</article>\n'
|
||||||
else:
|
else:
|
||||||
|
|
21
content.py
21
content.py
|
@ -398,7 +398,7 @@ def _update_common_emoji(base_dir: str, emoji_content: str) -> None:
|
||||||
|
|
||||||
def replace_emoji_from_tags(session, base_dir: str,
|
def replace_emoji_from_tags(session, base_dir: str,
|
||||||
content: str, tag: [], message_type: str,
|
content: str, tag: [], message_type: str,
|
||||||
debug: bool) -> str:
|
debug: bool, screen_readable: bool) -> str:
|
||||||
"""Uses the tags to replace :emoji: with html image markup
|
"""Uses the tags to replace :emoji: with html image markup
|
||||||
"""
|
"""
|
||||||
for tag_item in tag:
|
for tag_item in tag:
|
||||||
|
@ -429,8 +429,13 @@ def replace_emoji_from_tags(session, base_dir: str,
|
||||||
replaced = False
|
replaced = False
|
||||||
try:
|
try:
|
||||||
replace_char = chr(int("0x" + icon_name, 16))
|
replace_char = chr(int("0x" + icon_name, 16))
|
||||||
content = content.replace(tag_item['name'],
|
if not screen_readable:
|
||||||
replace_char)
|
replace_char = \
|
||||||
|
'<span aria-hidden="true">' + \
|
||||||
|
replace_char + '</span>'
|
||||||
|
content = \
|
||||||
|
content.replace(tag_item['name'],
|
||||||
|
replace_char)
|
||||||
replaced = True
|
replaced = True
|
||||||
except BaseException:
|
except BaseException:
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -479,6 +484,10 @@ def replace_emoji_from_tags(session, base_dir: str,
|
||||||
_update_common_emoji(base_dir,
|
_update_common_emoji(base_dir,
|
||||||
"0x" + icon_name)
|
"0x" + icon_name)
|
||||||
if icon_code_sequence:
|
if icon_code_sequence:
|
||||||
|
if not screen_readable:
|
||||||
|
icon_code_sequence = \
|
||||||
|
'<span aria-hidden="true">' + \
|
||||||
|
icon_code_sequence + '</span>'
|
||||||
content = content.replace(tag_item['name'],
|
content = content.replace(tag_item['name'],
|
||||||
icon_code_sequence)
|
icon_code_sequence)
|
||||||
|
|
||||||
|
@ -487,8 +496,12 @@ def replace_emoji_from_tags(session, base_dir: str,
|
||||||
html_class = 'emojiheader'
|
html_class = 'emojiheader'
|
||||||
if message_type == 'profile':
|
if message_type == 'profile':
|
||||||
html_class = 'emojiprofile'
|
html_class = 'emojiprofile'
|
||||||
|
if screen_readable:
|
||||||
|
emoji_tag_name = tag_item['name'].replace(':', '')
|
||||||
|
else:
|
||||||
|
emoji_tag_name = ''
|
||||||
emoji_html = "<img src=\"" + tag_item['icon']['url'] + "\" alt=\"" + \
|
emoji_html = "<img src=\"" + tag_item['icon']['url'] + "\" alt=\"" + \
|
||||||
tag_item['name'].replace(':', '') + \
|
emoji_tag_name + \
|
||||||
"\" align=\"middle\" class=\"" + html_class + "\"/>"
|
"\" align=\"middle\" class=\"" + html_class + "\"/>"
|
||||||
content = content.replace(tag_item['name'], emoji_html)
|
content = content.replace(tag_item['name'], emoji_html)
|
||||||
return content
|
return content
|
||||||
|
|
|
@ -18856,7 +18856,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.base_dir,
|
self.server.base_dir,
|
||||||
fields['message'],
|
fields['message'],
|
||||||
tags, 'content',
|
tags, 'content',
|
||||||
self.server.debug)
|
self.server.debug,
|
||||||
|
True)
|
||||||
|
|
||||||
post_json_object['object']['content'] = \
|
post_json_object['object']['content'] = \
|
||||||
fields['message']
|
fields['message']
|
||||||
|
|
2
posts.py
2
posts.py
|
@ -1445,7 +1445,7 @@ def _create_post_base(base_dir: str,
|
||||||
if nickname != 'news':
|
if nickname != 'news':
|
||||||
content = \
|
content = \
|
||||||
replace_emoji_from_tags(None, base_dir, content, tags, 'content',
|
replace_emoji_from_tags(None, base_dir, content, tags, 'content',
|
||||||
False)
|
False, True)
|
||||||
# remove replaced emoji
|
# remove replaced emoji
|
||||||
hashtags_dict_copy = hashtags_dict.copy()
|
hashtags_dict_copy = hashtags_dict.copy()
|
||||||
for tag_name, tag in hashtags_dict_copy.items():
|
for tag_name, tag in hashtags_dict_copy.items():
|
||||||
|
|
20
tests.py
20
tests.py
|
@ -3673,9 +3673,23 @@ def _test_addemoji(base_dir: str):
|
||||||
tags.append(tag)
|
tags.append(tag)
|
||||||
content = content_modified
|
content = content_modified
|
||||||
content_modified = \
|
content_modified = \
|
||||||
replace_emoji_from_tags(None, base_dir, content, tags, 'content', True)
|
replace_emoji_from_tags(None, base_dir, content, tags, 'content',
|
||||||
# print('content_modified: ' + content_modified)
|
True, True)
|
||||||
assert content_modified == '<p>Emoji 🍋 🍓 🍌</p>'
|
expected_content = '<p>Emoji 🍋 🍓 🍌</p>'
|
||||||
|
if content_modified != expected_content:
|
||||||
|
print('expected_content: ' + expected_content)
|
||||||
|
print('content_modified: ' + content_modified)
|
||||||
|
assert content_modified == expected_content
|
||||||
|
content_modified = \
|
||||||
|
replace_emoji_from_tags(None, base_dir, content, tags, 'content',
|
||||||
|
True, False)
|
||||||
|
expected_content = '<p>Emoji <span aria-hidden="true">🍋</span>' + \
|
||||||
|
' <span aria-hidden="true">🍓</span> ' + \
|
||||||
|
'<span aria-hidden="true">🍌</span></p>'
|
||||||
|
if content_modified != expected_content:
|
||||||
|
print('expected_content: ' + expected_content)
|
||||||
|
print('content_modified: ' + content_modified)
|
||||||
|
assert content_modified == expected_content
|
||||||
|
|
||||||
os.chdir(base_dir_original)
|
os.chdir(base_dir_original)
|
||||||
shutil.rmtree(base_dir_original + '/.tests',
|
shutil.rmtree(base_dir_original + '/.tests',
|
||||||
|
|
|
@ -2109,7 +2109,7 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
||||||
content_str = \
|
content_str = \
|
||||||
replace_emoji_from_tags(session, base_dir, content_str,
|
replace_emoji_from_tags(session, base_dir, content_str,
|
||||||
post_json_object['object']['tag'],
|
post_json_object['object']['tag'],
|
||||||
'content', False)
|
'content', False, True)
|
||||||
|
|
||||||
if is_muted:
|
if is_muted:
|
||||||
content_str = ''
|
content_str = ''
|
||||||
|
|
|
@ -984,12 +984,12 @@ def add_emoji_to_display_name(session, base_dir: str, http_prefix: str,
|
||||||
display_name = \
|
display_name = \
|
||||||
replace_emoji_from_tags(session, base_dir,
|
replace_emoji_from_tags(session, base_dir,
|
||||||
display_name, emoji_tags_list,
|
display_name, emoji_tags_list,
|
||||||
'post header', False)
|
'post header', False, False)
|
||||||
else:
|
else:
|
||||||
display_name = \
|
display_name = \
|
||||||
replace_emoji_from_tags(session, base_dir,
|
replace_emoji_from_tags(session, base_dir,
|
||||||
display_name, emoji_tags_list, 'profile',
|
display_name, emoji_tags_list, 'profile',
|
||||||
False)
|
False, False)
|
||||||
# print('TAG: display_name after tags 2: ' + display_name)
|
# print('TAG: display_name after tags 2: ' + display_name)
|
||||||
|
|
||||||
# remove any stray emoji
|
# remove any stray emoji
|
||||||
|
|
Loading…
Reference in New Issue