1
0

Improved text formatting

This commit is contained in:
Jon Michael Aanes 2024-11-03 23:57:15 +01:00
parent 352caa0fdd
commit 7568b862e2
Signed by: Jmaa
SSH Key Fingerprint: SHA256:Ab0GfHGCblESJx7JRE4fj4bFy/KRpeLhi41y4pF3sNA
3 changed files with 14 additions and 2 deletions

View File

@ -88,11 +88,12 @@ def is_adjacent_messages(first: Message, second: Message) -> bool:
and second.sent_at - first.sent_at <= MSG_ADJACENTCY_DIST
)
PUNCTUATION = ('.','?','!',',',':',';')
def merge_texts(text1: str, text2: str) -> str:
punctuated = text1.endswith('.?!,:')
punctuated = text1.endswith(PUNCTUATION)
# return text1 + (' ' if punctuated else '. ') + text2
return text1 + (' ' if punctuated else '. ') + '\n' + text2
return text1 + ('' if punctuated else '.') + '\n' + text2
def merge_adjacent_messages(messages: Iterable[Message]) -> list[Message]:

View File

@ -7,6 +7,8 @@ from .data import Message
def normalize_line(line: str) -> str:
line = re.sub(r'(<[\w ]+>)', r'`\1`', line)
line = re.sub(r'(\$\$\$)', r'`\1`', line)
line = re.sub(r'\s\s', ' ', line)
line = re.sub(r'\s+([.:;!?])', r'\1', line)
return line.strip()
def format_message_as_citation(out: list[str], msg: Message) -> None:

9
test/test_join.py Normal file
View File

@ -0,0 +1,9 @@
import datetime
from libpurple_to_markdown import merge_texts
def test_merge():
assert merge_texts('Hello World', 'Hello World.') == 'Hello World.\nHello World.'
assert merge_texts('Hello World.', 'Hello World.') == 'Hello World.\nHello World.'
assert merge_texts('Hello World?', 'Hello World.') == 'Hello World?\nHello World.'