mirror of https://gitlab.com/bashrc2/epicyon
Handle inline quotes
parent
9ad73fd6bb
commit
f068628770
23
content.py
23
content.py
|
|
@ -189,6 +189,27 @@ def html_replace_email_quote(content: str) -> str:
|
||||||
return _remove_quotes_within_quotes(new_content)
|
return _remove_quotes_within_quotes(new_content)
|
||||||
|
|
||||||
|
|
||||||
|
def html_replace_inline_quotes(content: str) -> str:
|
||||||
|
"""Replaces inline quotes within content with quotation marks
|
||||||
|
"""
|
||||||
|
if '<p class="quote-inline">' not in content:
|
||||||
|
return content
|
||||||
|
sections = content.split('<p class="quote-inline">')
|
||||||
|
ctr = 0
|
||||||
|
new_content = ''
|
||||||
|
for section in sections:
|
||||||
|
if ctr == 0:
|
||||||
|
new_content = section
|
||||||
|
ctr += 1
|
||||||
|
continue
|
||||||
|
if '</p>' in section:
|
||||||
|
new_content += '<p>"' + section.replace('</p>', '"</p>', 1)
|
||||||
|
else:
|
||||||
|
new_content += section
|
||||||
|
ctr += 1
|
||||||
|
return new_content
|
||||||
|
|
||||||
|
|
||||||
def html_replace_quote_marks(content: str) -> str:
|
def html_replace_quote_marks(content: str) -> str:
|
||||||
"""Replaces quotes with html formatting
|
"""Replaces quotes with html formatting
|
||||||
"hello" becomes <q>hello</q>
|
"hello" becomes <q>hello</q>
|
||||||
|
|
@ -1384,6 +1405,7 @@ def add_html_tags(base_dir: str, http_prefix: str,
|
||||||
by matching against known following accounts
|
by matching against known following accounts
|
||||||
"""
|
"""
|
||||||
if content.startswith('<p>'):
|
if content.startswith('<p>'):
|
||||||
|
content = html_replace_inline_quotes(content)
|
||||||
content = html_replace_email_quote(content)
|
content = html_replace_email_quote(content)
|
||||||
return html_replace_quote_marks(content)
|
return html_replace_quote_marks(content)
|
||||||
max_word_length = 40
|
max_word_length = 40
|
||||||
|
|
@ -1529,6 +1551,7 @@ def add_html_tags(base_dir: str, http_prefix: str,
|
||||||
content = remove_long_words(content, max_word_length, long_words_list)
|
content = remove_long_words(content, max_word_length, long_words_list)
|
||||||
content = limit_repeated_words(content, 6)
|
content = limit_repeated_words(content, 6)
|
||||||
content = html_replace_email_quote(content)
|
content = html_replace_email_quote(content)
|
||||||
|
content = html_replace_inline_quotes(content)
|
||||||
content = html_replace_quote_marks(content)
|
content = html_replace_quote_marks(content)
|
||||||
|
|
||||||
# undo replacements
|
# undo replacements
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ from utils import acct_dir
|
||||||
from utils import local_actor_url
|
from utils import local_actor_url
|
||||||
from utils import get_actor_from_post
|
from utils import get_actor_from_post
|
||||||
from content import html_replace_quote_marks
|
from content import html_replace_quote_marks
|
||||||
|
from content import html_replace_inline_quotes
|
||||||
|
|
||||||
SPEAKER_REMOVE_CHARS = ('.\n', '. ', ',', ';', '?', '!')
|
SPEAKER_REMOVE_CHARS = ('.\n', '. ', ',', ';', '?', '!')
|
||||||
|
|
||||||
|
|
@ -418,7 +419,8 @@ def speakable_text(http_prefix: str,
|
||||||
# replace some emoji before removing html
|
# replace some emoji before removing html
|
||||||
if ' <3' in content:
|
if ' <3' in content:
|
||||||
content = content.replace(' <3', ' ' + translate['heart'])
|
content = content.replace(' <3', ' ' + translate['heart'])
|
||||||
content = remove_html(html_replace_quote_marks(content))
|
content = remove_html(html_replace_inline_quotes(content))
|
||||||
|
content = html_replace_quote_marks(content)
|
||||||
detected_links: list[str] = []
|
detected_links: list[str] = []
|
||||||
content = speaker_replace_links(http_prefix,
|
content = speaker_replace_links(http_prefix,
|
||||||
nickname, domain, domain_full,
|
nickname, domain, domain_full,
|
||||||
|
|
@ -459,7 +461,8 @@ def _post_to_speaker_json(base_dir: str, http_prefix: str,
|
||||||
# replace some emoji before removing html
|
# replace some emoji before removing html
|
||||||
if ' <3' in content:
|
if ' <3' in content:
|
||||||
content = content.replace(' <3', ' ' + translate['heart'])
|
content = content.replace(' <3', ' ' + translate['heart'])
|
||||||
content = remove_html(html_replace_quote_marks(content))
|
content = remove_html(html_replace_inline_quotes(content))
|
||||||
|
content = html_replace_quote_marks(content)
|
||||||
content = speaker_replace_links(http_prefix,
|
content = speaker_replace_links(http_prefix,
|
||||||
nickname, domain, domain_full,
|
nickname, domain, domain_full,
|
||||||
content, translate, detected_links)
|
content, translate, detected_links)
|
||||||
|
|
|
||||||
22
tests.py
22
tests.py
|
|
@ -171,6 +171,7 @@ from content import limit_repeated_words
|
||||||
from content import switch_words
|
from content import switch_words
|
||||||
from content import extract_text_fields_in_post
|
from content import extract_text_fields_in_post
|
||||||
from content import html_replace_email_quote
|
from content import html_replace_email_quote
|
||||||
|
from content import html_replace_inline_quotes
|
||||||
from content import html_replace_quote_marks
|
from content import html_replace_quote_marks
|
||||||
from content import dangerous_css
|
from content import dangerous_css
|
||||||
from content import add_web_links
|
from content import add_web_links
|
||||||
|
|
@ -4673,7 +4674,7 @@ def _test_danger_markup():
|
||||||
assert not dangerous_markup(content, allow_local_network_access, [])
|
assert not dangerous_markup(content, allow_local_network_access, [])
|
||||||
|
|
||||||
|
|
||||||
def _run_html_replace_quote_marks():
|
def _test_html_replace_quote_marks():
|
||||||
print('html_replace_quote_marks')
|
print('html_replace_quote_marks')
|
||||||
test_str = 'The "cat" "sat" on the mat'
|
test_str = 'The "cat" "sat" on the mat'
|
||||||
result = html_replace_quote_marks(test_str)
|
result = html_replace_quote_marks(test_str)
|
||||||
|
|
@ -4692,6 +4693,22 @@ def _run_html_replace_quote_marks():
|
||||||
assert result == '“hello” <a href="somesite.html">“test” html</a>'
|
assert result == '“hello” <a href="somesite.html">“test” html</a>'
|
||||||
|
|
||||||
|
|
||||||
|
def _test_html_replace_inline_quotes():
|
||||||
|
print('html_replace_inline_quotes')
|
||||||
|
test_str = 'The <p class="quote-inline">cat</p> ' + \
|
||||||
|
'<p class="quote-inline">sat</p> on the mat'
|
||||||
|
result = html_replace_inline_quotes(test_str)
|
||||||
|
assert result == 'The <p>"cat"</p> <p>"sat"</p> on the mat'
|
||||||
|
|
||||||
|
test_str = 'The cat sat on the mat'
|
||||||
|
result = html_replace_inline_quotes(test_str)
|
||||||
|
assert result == 'The cat sat on the mat'
|
||||||
|
|
||||||
|
test_str = '<p class="quote-inline">hello</p>'
|
||||||
|
result = html_replace_inline_quotes(test_str)
|
||||||
|
assert result == '<p>"hello"</p>'
|
||||||
|
|
||||||
|
|
||||||
def _test_json_post_allows_comment():
|
def _test_json_post_allows_comment():
|
||||||
print('test_json_post_allows_comments')
|
print('test_json_post_allows_comments')
|
||||||
post_json_object = {
|
post_json_object = {
|
||||||
|
|
@ -9662,7 +9679,8 @@ def run_all_tests():
|
||||||
_test_valid_content_warning()
|
_test_valid_content_warning()
|
||||||
_test_remove_id_ending()
|
_test_remove_id_ending()
|
||||||
_test_json_post_allows_comment()
|
_test_json_post_allows_comment()
|
||||||
_run_html_replace_quote_marks()
|
_test_html_replace_inline_quotes()
|
||||||
|
_test_html_replace_quote_marks()
|
||||||
_test_danger_css(base_dir)
|
_test_danger_css(base_dir)
|
||||||
_test_danger_markup()
|
_test_danger_markup()
|
||||||
_test_strip_html()
|
_test_strip_html()
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,7 @@ from content import create_edits_html
|
||||||
from content import bold_reading_string
|
from content import bold_reading_string
|
||||||
from content import limit_repeated_words
|
from content import limit_repeated_words
|
||||||
from content import replace_emoji_from_tags
|
from content import replace_emoji_from_tags
|
||||||
|
from content import html_replace_inline_quotes
|
||||||
from content import html_replace_quote_marks
|
from content import html_replace_quote_marks
|
||||||
from content import html_replace_email_quote
|
from content import html_replace_email_quote
|
||||||
from content import remove_text_formatting
|
from content import remove_text_formatting
|
||||||
|
|
@ -3132,6 +3133,7 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
||||||
object_content = \
|
object_content = \
|
||||||
switch_words(base_dir, nickname, domain, object_content)
|
switch_words(base_dir, nickname, domain, object_content)
|
||||||
object_content = html_replace_email_quote(object_content)
|
object_content = html_replace_email_quote(object_content)
|
||||||
|
object_content = html_replace_inline_quotes(object_content)
|
||||||
object_content = html_replace_quote_marks(object_content)
|
object_content = html_replace_quote_marks(object_content)
|
||||||
object_content = \
|
object_content = \
|
||||||
format_mixed_right_to_left(object_content, system_language)
|
format_mixed_right_to_left(object_content, system_language)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue