mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-29 22:16:13 +02:00
Fix title splitting logic to account for both newlines and periods (#958)
* remove period parsing in title * fix title splitter * revert title-body switch * keep both splitting types * make black happy * make it lstrip not strip * fix title-body order for the last time * make black happy again * added test * second test for single line entry with punctuation * delete extra blank lines
This commit is contained in:
parent
63df95f2ea
commit
b575174a60
2 changed files with 19 additions and 6 deletions
13
jrnl/util.py
13
jrnl/util.py
|
@ -34,11 +34,10 @@ SENTENCE_SPLITTER = re.compile(
|
|||
[\'\u2019\"\u201D]? # an optional right quote,
|
||||
[\]\)]* # optional closing brackets and
|
||||
\s+ # a sequence of required spaces.
|
||||
| # Otherwise,
|
||||
\n # a sentence also terminates newlines.
|
||||
)""",
|
||||
re.VERBOSE,
|
||||
)
|
||||
SENTENCE_SPLITTER_ONLY_NEWLINE = re.compile("\n")
|
||||
|
||||
|
||||
class UserAbort(Exception):
|
||||
|
@ -281,7 +280,9 @@ def slugify(string):
|
|||
|
||||
def split_title(text):
|
||||
"""Splits the first sentence off from a text."""
|
||||
punkt = SENTENCE_SPLITTER.search(text)
|
||||
if not punkt:
|
||||
return text, ""
|
||||
return text[: punkt.end()].strip(), text[punkt.end() :].strip()
|
||||
sep = SENTENCE_SPLITTER_ONLY_NEWLINE.search(text.lstrip())
|
||||
if not sep:
|
||||
sep = SENTENCE_SPLITTER.search(text)
|
||||
if not sep:
|
||||
return text, ""
|
||||
return text[: sep.end()].strip(), text[sep.end() :].strip()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue