Improved text formatting
This commit is contained in:
parent
352caa0fdd
commit
7568b862e2
|
@ -88,11 +88,12 @@ def is_adjacent_messages(first: Message, second: Message) -> bool:
|
||||||
and second.sent_at - first.sent_at <= MSG_ADJACENTCY_DIST
|
and second.sent_at - first.sent_at <= MSG_ADJACENTCY_DIST
|
||||||
)
|
)
|
||||||
|
|
||||||
|
PUNCTUATION = ('.','?','!',',',':',';')
|
||||||
|
|
||||||
def merge_texts(text1: str, text2: str) -> str:
|
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 '. ') + text2
|
||||||
return text1 + (' ' if punctuated else '. ') + '\n' + text2
|
return text1 + ('' if punctuated else '.') + '\n' + text2
|
||||||
|
|
||||||
|
|
||||||
def merge_adjacent_messages(messages: Iterable[Message]) -> list[Message]:
|
def merge_adjacent_messages(messages: Iterable[Message]) -> list[Message]:
|
||||||
|
|
|
@ -7,6 +7,8 @@ from .data import Message
|
||||||
def normalize_line(line: str) -> str:
|
def normalize_line(line: str) -> str:
|
||||||
line = re.sub(r'(<[\w ]+>)', r'`\1`', line)
|
line = re.sub(r'(<[\w ]+>)', r'`\1`', line)
|
||||||
line = re.sub(r'(\$\$\$)', 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()
|
return line.strip()
|
||||||
|
|
||||||
def format_message_as_citation(out: list[str], msg: Message) -> None:
|
def format_message_as_citation(out: list[str], msg: Message) -> None:
|
||||||
|
|
9
test/test_join.py
Normal file
9
test/test_join.py
Normal 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.'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user