mirror of https://gitlab.com/bashrc2/epicyon
Allow bold markup for bold reading
parent
fd072faee7
commit
5320e7ed7b
|
@ -701,7 +701,7 @@ def replace_content_duplicates(content: str) -> str:
|
|||
return content
|
||||
|
||||
|
||||
def remove_text_formatting(content: str) -> str:
|
||||
def remove_text_formatting(content: str, bold_reading: bool) -> str:
|
||||
"""Removes markup for bold, italics, etc
|
||||
"""
|
||||
if is_pgp_encrypted(content) or contains_pgp_public_key(content):
|
||||
|
@ -709,6 +709,9 @@ def remove_text_formatting(content: str) -> str:
|
|||
if '<' not in content:
|
||||
return content
|
||||
for markup in REMOVE_MARKUP:
|
||||
if bold_reading:
|
||||
if markup == 'b':
|
||||
continue
|
||||
content = content.replace('<' + markup + '>', '')
|
||||
content = content.replace('</' + markup + '>', '')
|
||||
content = content.replace('<' + markup.upper() + '>', '')
|
||||
|
@ -1334,7 +1337,7 @@ def bold_reading_string(text: str) -> str:
|
|||
add_paragraph_markup = True
|
||||
paragraphs = text.split('\n')
|
||||
parag_ctr = 0
|
||||
new_text = ''
|
||||
new_text = ''
|
||||
for parag in paragraphs:
|
||||
words = parag.split(' ')
|
||||
new_parag = ''
|
||||
|
|
|
@ -683,7 +683,7 @@ def _read_local_box_post(session, nickname: str, domain: str,
|
|||
translate: {}, your_actor: str,
|
||||
domain_full: str, person_cache: {},
|
||||
signing_priv_key_pem: str,
|
||||
blocked_cache: {}) -> {}:
|
||||
blocked_cache: {}, bold_reading: bool) -> {}:
|
||||
"""Reads a post from the given timeline
|
||||
Returns the post json
|
||||
"""
|
||||
|
@ -724,7 +724,7 @@ def _read_local_box_post(session, nickname: str, domain: str,
|
|||
system_language,
|
||||
domain_full, person_cache,
|
||||
signing_priv_key_pem,
|
||||
blocked_cache)
|
||||
blocked_cache, bold_reading)
|
||||
if post_json_object2:
|
||||
if has_object_dict(post_json_object2):
|
||||
if post_json_object2['object'].get('attributedTo') and \
|
||||
|
@ -1356,6 +1356,8 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
"""Runs the desktop and screen reader client,
|
||||
which announces new inbox items
|
||||
"""
|
||||
bold_reading = False
|
||||
|
||||
# TODO: this should probably be retrieved somehow from the server
|
||||
signing_priv_key_pem = None
|
||||
|
||||
|
@ -1674,7 +1676,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
espeak, translate, your_actor,
|
||||
domain_full, person_cache,
|
||||
signing_priv_key_pem,
|
||||
blocked_cache)
|
||||
blocked_cache, bold_reading)
|
||||
print('')
|
||||
say_str = 'Press Enter to continue...'
|
||||
say_str2 = _highlight_text(say_str)
|
||||
|
@ -2464,7 +2466,8 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
|
|||
system_language,
|
||||
domain_full, person_cache,
|
||||
signing_priv_key_pem,
|
||||
blocked_cache)
|
||||
blocked_cache,
|
||||
bold_reading)
|
||||
if post_json_object2:
|
||||
post_json_object = post_json_object2
|
||||
if post_json_object:
|
||||
|
|
5
inbox.py
5
inbox.py
|
@ -2041,7 +2041,7 @@ def _receive_announce(recent_posts_cache: {},
|
|||
system_language,
|
||||
domain_full, person_cache,
|
||||
signing_priv_key_pem,
|
||||
blocked_cache)
|
||||
blocked_cache, bold_reading)
|
||||
if not post_json_object:
|
||||
print('WARN: unable to download announce: ' + str(message_json))
|
||||
not_in_onion = True
|
||||
|
@ -3681,7 +3681,8 @@ def _inbox_after_initial(server,
|
|||
twitter_replacement_domain,
|
||||
allow_local_network_access,
|
||||
recent_posts_cache, debug, system_language,
|
||||
domain_full, person_cache, signing_priv_key_pem):
|
||||
domain_full, person_cache, signing_priv_key_pem,
|
||||
bold_reading):
|
||||
# media index will be updated
|
||||
update_index_list.append('tlmedia')
|
||||
if is_blog_post(post_json_object):
|
||||
|
|
10
outbox.py
10
outbox.py
|
@ -219,6 +219,10 @@ def post_message_to_outbox(session, translate: {},
|
|||
domain, port,
|
||||
message_json)
|
||||
|
||||
bold_reading = False
|
||||
if server.bold_reading.get(post_to_nickname):
|
||||
bold_reading = True
|
||||
|
||||
# check that the outgoing post doesn't contain any markup
|
||||
# which can be used to implement exploits
|
||||
if has_object_dict(message_json):
|
||||
|
@ -430,7 +434,8 @@ def post_message_to_outbox(session, translate: {},
|
|||
recent_posts_cache, debug,
|
||||
system_language,
|
||||
domain_full, person_cache,
|
||||
signing_priv_key_pem):
|
||||
signing_priv_key_pem,
|
||||
bold_reading):
|
||||
inbox_update_index('tlmedia', base_dir,
|
||||
post_to_nickname + '@' + domain,
|
||||
saved_filename, debug)
|
||||
|
@ -461,9 +466,6 @@ def post_message_to_outbox(session, translate: {},
|
|||
if os.path.isfile(saved_filename.replace('.json', '') +
|
||||
'.mitm'):
|
||||
mitm = True
|
||||
bold_reading = False
|
||||
if server.bold_reading.get(post_to_nickname):
|
||||
bold_reading = True
|
||||
individual_post_as_html(signing_priv_key_pem,
|
||||
False, recent_posts_cache,
|
||||
max_recent_posts,
|
||||
|
|
9
posts.py
9
posts.py
|
@ -3683,7 +3683,8 @@ def is_image_media(session, base_dir: str, http_prefix: str,
|
|||
recent_posts_cache: {}, debug: bool,
|
||||
system_language: str,
|
||||
domain_full: str, person_cache: {},
|
||||
signing_priv_key_pem: str) -> bool:
|
||||
signing_priv_key_pem: str,
|
||||
bold_reading: bool) -> bool:
|
||||
"""Returns true if the given post has attached image media
|
||||
"""
|
||||
if post_json_object['type'] == 'Announce':
|
||||
|
@ -3699,7 +3700,7 @@ def is_image_media(session, base_dir: str, http_prefix: str,
|
|||
system_language,
|
||||
domain_full, person_cache,
|
||||
signing_priv_key_pem,
|
||||
blocked_cache)
|
||||
blocked_cache, bold_reading)
|
||||
if post_json_announce:
|
||||
post_json_object = post_json_announce
|
||||
if post_json_object['type'] != 'Create':
|
||||
|
@ -4765,7 +4766,7 @@ def download_announce(session, base_dir: str, http_prefix: str,
|
|||
system_language: str,
|
||||
domain_full: str, person_cache: {},
|
||||
signing_priv_key_pem: str,
|
||||
blocked_cache: {}) -> {}:
|
||||
blocked_cache: {}, bold_reading: bool) -> {}:
|
||||
"""Download the post referenced by an announce
|
||||
"""
|
||||
if not post_json_object.get('object'):
|
||||
|
@ -4972,7 +4973,7 @@ def download_announce(session, base_dir: str, http_prefix: str,
|
|||
content_str = limit_repeated_words(content_str, 6)
|
||||
|
||||
# remove text formatting, such as bold/italics
|
||||
content_str = remove_text_formatting(content_str)
|
||||
content_str = remove_text_formatting(content_str, bold_reading)
|
||||
|
||||
# set the content after santitization
|
||||
announced_json['content'] = content_str
|
||||
|
|
4
tests.py
4
tests.py
|
@ -3728,10 +3728,10 @@ def _test_recent_posts_cache():
|
|||
def _test_remove_txt_formatting():
|
||||
print('test_remove_txt_formatting')
|
||||
test_str = '<p>Text without formatting</p>'
|
||||
result_str = remove_text_formatting(test_str)
|
||||
result_str = remove_text_formatting(test_str, False)
|
||||
assert result_str == test_str
|
||||
test_str = '<p>Text <i>with</i> <h3>formatting</h3></p>'
|
||||
result_str = remove_text_formatting(test_str)
|
||||
result_str = remove_text_formatting(test_str, False)
|
||||
assert result_str == '<p>Text with formatting</p>'
|
||||
|
||||
|
||||
|
|
|
@ -1604,7 +1604,7 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
system_language,
|
||||
domain_full, person_cache,
|
||||
signing_priv_key_pem,
|
||||
blocked_cache)
|
||||
blocked_cache, bold_reading)
|
||||
if not post_json_announce:
|
||||
# if the announce could not be downloaded then mark it as rejected
|
||||
announced_post_id = remove_id_ending(post_json_object['id'])
|
||||
|
@ -1987,20 +1987,18 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
|
||||
_log_post_timing(enable_timing_log, post_start_time, '16')
|
||||
|
||||
print('Test bold_reading 1 ' + str(bold_reading))
|
||||
if not is_pgp_encrypted(content_str):
|
||||
if not is_patch:
|
||||
# Add bold text
|
||||
print('Test bold_reading 2 ' + str(bold_reading))
|
||||
if bold_reading and \
|
||||
not displaying_ciphertext and \
|
||||
not post_is_blog:
|
||||
content_str = bold_reading_string(content_str)
|
||||
print('Test bold_reading 3 ' + content_str)
|
||||
|
||||
object_content = \
|
||||
remove_long_words(content_str, 40, [])
|
||||
object_content = remove_text_formatting(object_content)
|
||||
object_content = \
|
||||
remove_text_formatting(object_content, bold_reading)
|
||||
object_content = limit_repeated_words(object_content, 6)
|
||||
object_content = \
|
||||
switch_words(base_dir, nickname, domain, object_content)
|
||||
|
|
Loading…
Reference in New Issue