mirror of https://gitlab.com/bashrc2/epicyon
Remove css style from post content
This could otherwise mess up the UImerge-requests/30/head
parent
5e30830c04
commit
2d9f4a3681
18
tests.py
18
tests.py
|
@ -54,6 +54,7 @@ from follow import clear_followers
|
||||||
from follow import send_follow_request_via_server
|
from follow import send_follow_request_via_server
|
||||||
from follow import send_unfollow_request_via_server
|
from follow import send_unfollow_request_via_server
|
||||||
from siteactive import site_is_active
|
from siteactive import site_is_active
|
||||||
|
from utils import remove_style_within_html
|
||||||
from utils import html_tag_has_closing
|
from utils import html_tag_has_closing
|
||||||
from utils import remove_inverted_text
|
from utils import remove_inverted_text
|
||||||
from utils import remove_square_capitals
|
from utils import remove_square_capitals
|
||||||
|
@ -7865,6 +7866,22 @@ def _test_html_closing_tag() -> None:
|
||||||
assert not html_tag_has_closing('code', content)
|
assert not html_tag_has_closing('code', content)
|
||||||
|
|
||||||
|
|
||||||
|
def _test_remove_style() -> None:
|
||||||
|
print('remove_style')
|
||||||
|
html_str = '<p>this is a test</p>'
|
||||||
|
result = remove_style_within_html(html_str)
|
||||||
|
assert result == html_str
|
||||||
|
|
||||||
|
html_str = \
|
||||||
|
'<span style="font-size: 200%" class="mfm _mfm_x2_">something</span>'
|
||||||
|
result = remove_style_within_html(html_str)
|
||||||
|
expected = \
|
||||||
|
'<span class="mfm _mfm_x2_">something</span>'
|
||||||
|
if result != expected:
|
||||||
|
print(expected + '\n\n' + 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...')
|
||||||
|
@ -7882,6 +7899,7 @@ def run_all_tests():
|
||||||
_test_checkbox_names()
|
_test_checkbox_names()
|
||||||
_test_thread_functions()
|
_test_thread_functions()
|
||||||
_test_functions()
|
_test_functions()
|
||||||
|
_test_remove_style()
|
||||||
_test_html_closing_tag()
|
_test_html_closing_tag()
|
||||||
_test_replace_remote_tags()
|
_test_replace_remote_tags()
|
||||||
_test_replace_variable()
|
_test_replace_variable()
|
||||||
|
|
20
utils.py
20
utils.py
|
@ -655,6 +655,26 @@ def remove_html(content: str) -> str:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def remove_style_within_html(content: str) -> str:
|
||||||
|
"""Removes style="something" within html post content.
|
||||||
|
Used to ensure that styles
|
||||||
|
"""
|
||||||
|
if '<' not in content:
|
||||||
|
return content
|
||||||
|
if ' style="' not in content:
|
||||||
|
return content
|
||||||
|
sections = content.split(' style="')
|
||||||
|
result = ''
|
||||||
|
ctr = 0
|
||||||
|
for section_text in sections:
|
||||||
|
if ctr > 0:
|
||||||
|
result += section_text.split('"', 1)[1]
|
||||||
|
else:
|
||||||
|
result = section_text
|
||||||
|
ctr = 1
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
def first_paragraph_from_string(content: str) -> str:
|
def first_paragraph_from_string(content: str) -> str:
|
||||||
"""Get the first paragraph from a blog post
|
"""Get the first paragraph from a blog post
|
||||||
to be used as a summary in the newswire feed
|
to be used as a summary in the newswire feed
|
||||||
|
|
|
@ -25,6 +25,7 @@ from posts import post_is_muted
|
||||||
from posts import get_person_box
|
from posts import get_person_box
|
||||||
from posts import download_announce
|
from posts import download_announce
|
||||||
from posts import populate_replies_json
|
from posts import populate_replies_json
|
||||||
|
from utils import remove_style_within_html
|
||||||
from utils import license_link_from_name
|
from utils import license_link_from_name
|
||||||
from utils import dont_speak_hashtags
|
from utils import dont_speak_hashtags
|
||||||
from utils import remove_eol
|
from utils import remove_eol
|
||||||
|
@ -2423,6 +2424,10 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
||||||
languages_understood = get_actor_languages_list(actor_json)
|
languages_understood = get_actor_languages_list(actor_json)
|
||||||
content_str = get_content_from_post(post_json_object, system_language,
|
content_str = get_content_from_post(post_json_object, system_language,
|
||||||
languages_understood)
|
languages_understood)
|
||||||
|
|
||||||
|
# remove any css styling within the post itself
|
||||||
|
content_str = remove_style_within_html(content_str)
|
||||||
|
|
||||||
content_language = \
|
content_language = \
|
||||||
get_language_from_post(post_json_object, system_language,
|
get_language_from_post(post_json_object, system_language,
|
||||||
languages_understood)
|
languages_understood)
|
||||||
|
|
Loading…
Reference in New Issue