mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +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
|
@ -26,6 +26,18 @@ Feature: Basic reading and writing to a journal
|
|||
| There is a blank line above this.
|
||||
"""
|
||||
|
||||
Scenario: Multiline entry with punctuation
|
||||
Given we use the config "basic.yaml"
|
||||
When we run "jrnl This is. the title\\n This is the second line"
|
||||
and we run "jrnl -n 1"
|
||||
Then the output should contain "This is. the title"
|
||||
|
||||
Scenario: Single line entry with punctuation
|
||||
Given we use the config "basic.yaml"
|
||||
When we run "jrnl This is. the title"
|
||||
and we run "jrnl -n 1"
|
||||
Then the output should contain "| the title"
|
||||
|
||||
Scenario: Writing an entry from command line
|
||||
Given we use the config "basic.yaml"
|
||||
When we run "jrnl 23 july 2013: A cold and stormy day. I ate crisps on the sofa."
|
||||
|
|
11
jrnl/util.py
11
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:
|
||||
sep = SENTENCE_SPLITTER_ONLY_NEWLINE.search(text.lstrip())
|
||||
if not sep:
|
||||
sep = SENTENCE_SPLITTER.search(text)
|
||||
if not sep:
|
||||
return text, ""
|
||||
return text[: punkt.end()].strip(), text[punkt.end() :].strip()
|
||||
return text[: sep.end()].strip(), text[sep.end() :].strip()
|
||||
|
|
Loading…
Add table
Reference in a new issue