Less indentation

main
Bob Mottram 2024-08-30 13:25:23 +01:00
parent 577bf923c1
commit da66e2744d
1 changed files with 108 additions and 107 deletions

View File

@ -472,76 +472,74 @@ def replace_emoji_from_tags(session, base_dir: str,
if not tag_url: if not tag_url:
continue continue
icon_name = tag_url.split('/')[-1] icon_name = tag_url.split('/')[-1]
if icon_name: if len(icon_name) > 1:
if len(icon_name) > 1: if icon_name[0].isdigit() and '.' in icon_name:
if icon_name[0].isdigit(): icon_name = icon_name.split('.')[0]
if '.' in icon_name: # see https://unicode.org/
icon_name = icon_name.split('.')[0] # emoji/charts/full-emoji-list.html
# see https://unicode.org/ if '-' not in icon_name:
# emoji/charts/full-emoji-list.html # a single code
if '-' not in icon_name: replaced = False
# a single code try:
replaced = False replace_char = chr(int("0x" + icon_name, 16))
try: if not screen_readable:
replace_char = chr(int("0x" + icon_name, 16)) replace_char = \
if not screen_readable: '<span aria-hidden="true">' + \
replace_char = \ replace_char + '</span>'
'<span aria-hidden="true">' + \ content = \
replace_char + '</span>' content.replace(tag_item['name'],
content = \ replace_char)
content.replace(tag_item['name'], replaced = True
replace_char) except BaseException:
replaced = True if debug:
except BaseException: print('EX: replace_emoji_from_tags 1 ' +
if debug: 'no conversion of ' +
print('EX: replace_emoji_from_tags 1 ' + str(icon_name) + ' to chr ' +
'no conversion of ' + tag_item['name'] + ' ' +
str(icon_name) + ' to chr ' + tag_url)
tag_item['name'] + ' ' + if not replaced:
tag_url) _save_custom_emoji(session, base_dir,
if not replaced: tag_item['name'],
_save_custom_emoji(session, base_dir, tag_url, debug)
tag_item['name'], _update_common_emoji(base_dir, icon_name)
tag_url, debug) else:
_update_common_emoji(base_dir, icon_name) _update_common_emoji(base_dir,
else: "0x" + icon_name)
_update_common_emoji(base_dir, else:
"0x" + icon_name) # sequence of codes
else: icon_codes = icon_name.split('-')
# sequence of codes icon_code_sequence = ''
icon_codes = icon_name.split('-') for icode in icon_codes:
replaced = False
try:
icon_code_sequence += chr(int("0x" +
icode, 16))
replaced = True
except BaseException:
icon_code_sequence = '' icon_code_sequence = ''
for icode in icon_codes: if debug:
replaced = False print('EX: ' +
try: 'replace_emoji_from_tags 2 ' +
icon_code_sequence += chr(int("0x" + 'no conversion of ' +
icode, 16)) str(icode) + ' to chr ' +
replaced = True tag_item['name'] + ' ' +
except BaseException: tag_url)
icon_code_sequence = '' if not replaced:
if debug: _save_custom_emoji(session, base_dir,
print('EX: ' + tag_item['name'],
'replace_emoji_from_tags 2 ' + tag_url, debug)
'no conversion of ' + _update_common_emoji(base_dir,
str(icode) + ' to chr ' + icon_name)
tag_item['name'] + ' ' + else:
tag_url) _update_common_emoji(base_dir,
if not replaced: "0x" + icon_name)
_save_custom_emoji(session, base_dir, if icon_code_sequence:
tag_item['name'], if not screen_readable:
tag_url, debug) icon_code_sequence = \
_update_common_emoji(base_dir, '<span aria-hidden="true">' + \
icon_name) icon_code_sequence + '</span>'
else: content = content.replace(tag_item['name'],
_update_common_emoji(base_dir, icon_code_sequence)
"0x" + icon_name)
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'],
icon_code_sequence)
html_class = 'emoji' html_class = 'emoji'
if message_type == 'post header': if message_type == 'post header':
@ -950,24 +948,25 @@ def _add_mention(base_dir: str, word_str: str, http_prefix: str,
if '@' not in follow: if '@' not in follow:
continue continue
follow_nick = follow.split('@')[0] follow_nick = follow.split('@')[0]
if possible_nickname == follow_nick: if possible_nickname != follow_nick:
follow_str = remove_eol(follow) continue
replace_domain = follow_str.split('@')[1] follow_str = remove_eol(follow)
recipient_actor = \ replace_domain = follow_str.split('@')[1]
_mention_to_url(base_dir, http_prefix, recipient_actor = \
replace_domain, possible_nickname) _mention_to_url(base_dir, http_prefix,
if recipient_actor not in recipients: replace_domain, possible_nickname)
recipients.append(recipient_actor) if recipient_actor not in recipients:
tags[word_str] = { recipients.append(recipient_actor)
'href': recipient_actor, tags[word_str] = {
'name': word_str, 'href': recipient_actor,
'type': 'Mention' 'name': word_str,
} 'type': 'Mention'
replace_mentions[word_str] = \ }
"<span class=\"h-card\"><a href=\"" + recipient_actor + \ replace_mentions[word_str] = \
"\" tabindex=\"10\" class=\"u-url mention\">@<span>" + \ "<span class=\"h-card\"><a href=\"" + recipient_actor + \
possible_nickname + "</span></a></span>" "\" tabindex=\"10\" class=\"u-url mention\">@<span>" + \
return True possible_nickname + "</span></a></span>"
return True
# try replacing petnames with mentions # try replacing petnames with mentions
follow_ctr = 0 follow_ctr = 0
for follow in following: for follow in following:
@ -976,26 +975,28 @@ def _add_mention(base_dir: str, word_str: str, http_prefix: str,
continue continue
pet = remove_eol(petnames[follow_ctr]) pet = remove_eol(petnames[follow_ctr])
if pet: if pet:
if possible_nickname == pet: if possible_nickname != pet:
follow_str = remove_eol(follow) follow_ctr += 1
replace_nickname = follow_str.split('@')[0] continue
replace_domain = follow_str.split('@')[1] follow_str = remove_eol(follow)
recipient_actor = \ replace_nickname = follow_str.split('@')[0]
_mention_to_url(base_dir, http_prefix, replace_domain = follow_str.split('@')[1]
replace_domain, replace_nickname) recipient_actor = \
if recipient_actor not in recipients: _mention_to_url(base_dir, http_prefix,
recipients.append(recipient_actor) replace_domain, replace_nickname)
tags[word_str] = { if recipient_actor not in recipients:
'href': recipient_actor, recipients.append(recipient_actor)
'name': word_str, tags[word_str] = {
'type': 'Mention' 'href': recipient_actor,
} 'name': word_str,
replace_mentions[word_str] = \ 'type': 'Mention'
"<span class=\"h-card\"><a href=\"" + \ }
recipient_actor + "\" tabindex=\"10\" " + \ replace_mentions[word_str] = \
"class=\"u-url mention\">@<span>" + \ "<span class=\"h-card\"><a href=\"" + \
replace_nickname + "</span></a></span>" recipient_actor + "\" tabindex=\"10\" " + \
return True "class=\"u-url mention\">@<span>" + \
replace_nickname + "</span></a></span>"
return True
follow_ctr += 1 follow_ctr += 1
return False return False
possible_nickname = None possible_nickname = None