mirror of https://gitlab.com/bashrc2/epicyon
Combining lines within paragraphs to work around the lack of word-wrap within Lynx textarea
parent
655fb521be
commit
4e72f36a1c
18
content.py
18
content.py
|
@ -1474,6 +1474,22 @@ def save_media_in_form_post(media_bytes, debug: bool,
|
||||||
return filename, attachment_media_type
|
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', ' ')
|
||||||
|
para = para.replace(' ', ' ')
|
||||||
|
if ctr > 0:
|
||||||
|
result += '\n\n'
|
||||||
|
result += para
|
||||||
|
ctr += 1
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def extract_text_fields_in_post(post_bytes, boundary: str, debug: bool,
|
def extract_text_fields_in_post(post_bytes, boundary: str, debug: bool,
|
||||||
unit_test_data: str = None) -> {}:
|
unit_test_data: str = None) -> {}:
|
||||||
"""Returns a dictionary containing the text fields of a http form POST
|
"""Returns a dictionary containing the text fields of a http form POST
|
||||||
|
@ -1546,6 +1562,8 @@ def extract_text_fields_in_post(post_bytes, boundary: str, debug: bool,
|
||||||
post_value += '\n'
|
post_value += '\n'
|
||||||
post_value += post_lines[line]
|
post_value += post_lines[line]
|
||||||
fields[post_key] = urllib.parse.unquote(post_value)
|
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
|
return fields
|
||||||
|
|
||||||
|
|
||||||
|
|
38
tests.py
38
tests.py
|
@ -133,6 +133,7 @@ from inbox import valid_inbox
|
||||||
from inbox import valid_inbox_filenames
|
from inbox import valid_inbox_filenames
|
||||||
from inbox import cache_svg_images
|
from inbox import cache_svg_images
|
||||||
from categories import guess_hashtag_category
|
from categories import guess_hashtag_category
|
||||||
|
from content import combine_textarea_lines
|
||||||
from content import detect_dogwhistles
|
from content import detect_dogwhistles
|
||||||
from content import remove_script
|
from content import remove_script
|
||||||
from content import create_edits_html
|
from content import create_edits_html
|
||||||
|
@ -7412,6 +7413,42 @@ def _test_text_standardize():
|
||||||
assert result == expected
|
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 = text
|
||||||
|
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.\n\nSecond 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.\n\nSecond line.'
|
||||||
|
result = combine_textarea_lines(text)
|
||||||
|
if result != expected:
|
||||||
|
print('expected: ' + expected)
|
||||||
|
print('result: ' + result)
|
||||||
|
assert result == expected
|
||||||
|
|
||||||
|
|
||||||
def run_all_tests():
|
def run_all_tests():
|
||||||
base_dir = os.getcwd()
|
base_dir = os.getcwd()
|
||||||
print('Running tests...')
|
print('Running tests...')
|
||||||
|
@ -7429,6 +7466,7 @@ def run_all_tests():
|
||||||
_test_checkbox_names()
|
_test_checkbox_names()
|
||||||
_test_thread_functions()
|
_test_thread_functions()
|
||||||
_test_functions()
|
_test_functions()
|
||||||
|
_test_combine_lines()
|
||||||
_test_text_standardize()
|
_test_text_standardize()
|
||||||
_test_dogwhistles()
|
_test_dogwhistles()
|
||||||
_test_remove_end_of_line()
|
_test_remove_end_of_line()
|
||||||
|
|
Loading…
Reference in New Issue