mirror of https://gitlab.com/bashrc2/epicyon
Merge branch 'main' of gitlab.com:bashrc2/epicyon
commit
edd3a89f68
24
content.py
24
content.py
|
@ -1474,6 +1474,28 @@ def save_media_in_form_post(media_bytes, debug: bool,
|
|||
return filename, attachment_media_type
|
||||
|
||||
|
||||
def combine_textarea_lines(text: str) -> str:
|
||||
"""Combines separate lines
|
||||
"""
|
||||
result = ''
|
||||
ctr = 0
|
||||
paragraphs = text.split('\n\n')
|
||||
for para in paragraphs:
|
||||
para = para.replace('\n* ', '***BULLET POINT*** ')
|
||||
para = para.replace('\n * ', '***BULLET POINT*** ')
|
||||
para = para.replace('\n- ', '***DASH POINT*** ')
|
||||
para = para.replace('\n - ', '***DASH POINT*** ')
|
||||
para = para.replace('\n', ' ')
|
||||
para = para.replace(' ', ' ')
|
||||
para = para.replace('***BULLET POINT*** ', '\n* ')
|
||||
para = para.replace('***DASH POINT*** ', '\n- ')
|
||||
if ctr > 0:
|
||||
result += '</p><p>'
|
||||
result += para
|
||||
ctr += 1
|
||||
return result
|
||||
|
||||
|
||||
def extract_text_fields_in_post(post_bytes, boundary: str, debug: bool,
|
||||
unit_test_data: str = None) -> {}:
|
||||
"""Returns a dictionary containing the text fields of a http form POST
|
||||
|
@ -1546,6 +1568,8 @@ def extract_text_fields_in_post(post_bytes, boundary: str, debug: bool,
|
|||
post_value += '\n'
|
||||
post_value += post_lines[line]
|
||||
fields[post_key] = urllib.parse.unquote(post_value)
|
||||
if boundary == '--LYNX' and post_key in ('message', 'bio'):
|
||||
fields[post_key] = combine_textarea_lines(fields[post_key])
|
||||
return fields
|
||||
|
||||
|
||||
|
|
48
tests.py
48
tests.py
|
@ -133,6 +133,7 @@ from inbox import valid_inbox
|
|||
from inbox import valid_inbox_filenames
|
||||
from inbox import cache_svg_images
|
||||
from categories import guess_hashtag_category
|
||||
from content import combine_textarea_lines
|
||||
from content import detect_dogwhistles
|
||||
from content import remove_script
|
||||
from content import create_edits_html
|
||||
|
@ -7412,6 +7413,52 @@ def _test_text_standardize():
|
|||
assert result == expected
|
||||
|
||||
|
||||
def _test_combine_lines():
|
||||
print('combine_lines')
|
||||
text = 'This is a test'
|
||||
expected = text
|
||||
result = combine_textarea_lines(text)
|
||||
if result != expected:
|
||||
print('expected: ' + expected)
|
||||
print('result: ' + result)
|
||||
assert result == expected
|
||||
|
||||
text = 'First line.\n\nSecond line.'
|
||||
expected = 'First line.</p><p>Second line.'
|
||||
result = combine_textarea_lines(text)
|
||||
if result != expected:
|
||||
print('expected: ' + expected)
|
||||
print('result: ' + result)
|
||||
assert result == expected
|
||||
|
||||
text = 'First\nline.\n\nSecond\nline.'
|
||||
expected = 'First line.</p><p>Second line.'
|
||||
result = combine_textarea_lines(text)
|
||||
if result != expected:
|
||||
print('expected: ' + expected)
|
||||
print('result: ' + result)
|
||||
assert result == expected
|
||||
|
||||
# with extra space
|
||||
text = 'First\nline.\n\nSecond \nline.'
|
||||
expected = 'First line.</p><p>Second line.'
|
||||
result = combine_textarea_lines(text)
|
||||
if result != expected:
|
||||
print('expected: ' + expected)
|
||||
print('result: ' + result)
|
||||
assert result == expected
|
||||
|
||||
text = 'Introduction blurb.\n\n* List item 1\n' + \
|
||||
'* List item 2\n* List item 3\n\nFinal blurb.'
|
||||
expected = 'Introduction blurb.</p><p>* List item 1\n' + \
|
||||
'* List item 2\n* List item 3</p><p>Final blurb.'
|
||||
result = combine_textarea_lines(text)
|
||||
if result != expected:
|
||||
print('expected: ' + expected)
|
||||
print('result: ' + result)
|
||||
assert result == expected
|
||||
|
||||
|
||||
def run_all_tests():
|
||||
base_dir = os.getcwd()
|
||||
print('Running tests...')
|
||||
|
@ -7429,6 +7476,7 @@ def run_all_tests():
|
|||
_test_checkbox_names()
|
||||
_test_thread_functions()
|
||||
_test_functions()
|
||||
_test_combine_lines()
|
||||
_test_text_standardize()
|
||||
_test_dogwhistles()
|
||||
_test_remove_end_of_line()
|
||||
|
|
|
@ -914,11 +914,11 @@ def html_new_post(css_cache: {}, media_instance: bool, translate: {},
|
|||
if in_reply_to or endpoint == 'newdm':
|
||||
if in_reply_to:
|
||||
new_post_form += \
|
||||
' <label class="labels">' + placeholder_mentions + \
|
||||
' <br><label class="labels">' + placeholder_mentions + \
|
||||
'</label><br>\n'
|
||||
else:
|
||||
new_post_form += \
|
||||
' <a href="/users/' + nickname + \
|
||||
' <br><a href="/users/' + nickname + \
|
||||
'/followingaccounts" title="' + \
|
||||
translate['Show a list of addresses to send to'] + '">' \
|
||||
'<label class="labels">' + \
|
||||
|
|
Loading…
Reference in New Issue