Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix title splitting logic to account for both newlines and periods #958

Merged
merged 11 commits into from
May 27, 2020
12 changes: 12 additions & 0 deletions features/core.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
13 changes: 7 additions & 6 deletions jrnl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@
[\'\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):
Expand Down Expand Up @@ -263,7 +262,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()