From a3e096edfd600f8d6342bfad5a299b50b33e9604 Mon Sep 17 00:00:00 2001 From: Eshan Ramesh Date: Tue, 19 May 2020 15:09:47 -0400 Subject: [PATCH 01/11] remove period parsing in title --- jrnl/util.py | 1 - 1 file changed, 1 deletion(-) diff --git a/jrnl/util.py b/jrnl/util.py index 8033306bc..f75d9fb17 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -29,7 +29,6 @@ SENTENCE_SPLITTER = re.compile( r""" ( # A sentence ends at one of two sequences: - [.!?\u203C\u203D\u2047\u2048\u2049\u3002\uFE52\uFE57\uFF01\uFF0E\uFF1F\uFF61] # Either, a sequence starting with a sentence terminal, [\'\u2019\"\u201D]? # an optional right quote, [\]\)]* # optional closing brackets and \s+ # a sequence of required spaces. From cd6e532568aaf5f925e8e1f7b7d1ab8df979ea75 Mon Sep 17 00:00:00 2001 From: Eshan Ramesh Date: Tue, 19 May 2020 16:03:38 -0400 Subject: [PATCH 02/11] fix title splitter --- jrnl/util.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/jrnl/util.py b/jrnl/util.py index f75d9fb17..2a685be42 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -26,17 +26,7 @@ # Based on Segtok by Florian Leitner # https://github.com/fnl/segtok -SENTENCE_SPLITTER = re.compile( - r""" -( # A sentence ends at one of two sequences: - [\'\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 = re.compile("\n") class UserAbort(Exception): @@ -262,7 +252,7 @@ def slugify(string): def split_title(text): """Splits the first sentence off from a text.""" - punkt = SENTENCE_SPLITTER.search(text) + punkt = SENTENCE_SPLITTER.search(text.strip()) if not punkt: - return text, "" + return text,"" return text[: punkt.end()].strip(), text[punkt.end() :].strip() From aeafcd36c9214e8a70215eee6dfa01abd36babab Mon Sep 17 00:00:00 2001 From: Eshan Ramesh Date: Tue, 19 May 2020 16:08:42 -0400 Subject: [PATCH 03/11] revert title-body switch --- jrnl/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jrnl/util.py b/jrnl/util.py index 2a685be42..05d6d2caa 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -254,5 +254,5 @@ def split_title(text): """Splits the first sentence off from a text.""" punkt = SENTENCE_SPLITTER.search(text.strip()) if not punkt: - return text,"" + return "",text return text[: punkt.end()].strip(), text[punkt.end() :].strip() From 3375accf33268ffae6a34a3f951cc824f0ea2099 Mon Sep 17 00:00:00 2001 From: Eshan Ramesh Date: Tue, 19 May 2020 16:18:08 -0400 Subject: [PATCH 04/11] keep both splitting types --- jrnl/util.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/jrnl/util.py b/jrnl/util.py index 05d6d2caa..ba46c3da7 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -26,7 +26,17 @@ # Based on Segtok by Florian Leitner # https://github.com/fnl/segtok -SENTENCE_SPLITTER = re.compile("\n") +SENTENCE_SPLITTER = re.compile( + r""" +( # A sentence ends at one of two sequences: + [.!?\u203C\u203D\u2047\u2048\u2049\u3002\uFE52\uFE57\uFF01\uFF0E\uFF1F\uFF61] # Either, a sequence starting with a sentence terminal, + [\'\u2019\"\u201D]? # an optional right quote, + [\]\)]* # optional closing brackets and + \s+ # a sequence of required spaces. +)""", + re.VERBOSE, +) +SENTENCE_SPLITTER_ONLY_NEWLINE = re.compile("\n") class UserAbort(Exception): @@ -252,7 +262,9 @@ def slugify(string): def split_title(text): """Splits the first sentence off from a text.""" - punkt = SENTENCE_SPLITTER.search(text.strip()) - if not punkt: - return "",text - return text[: punkt.end()].strip(), text[punkt.end() :].strip() + sep = SENTENCE_SPLITTER_ONLY_NEWLINE.search(text.strip()) + if not sep: + sep = SENTENCE_SPLITTER.search(text) + if not sep: + return "",text + return text[: sep.end()].strip(), text[sep.end() :].strip() From 7521960f1c86d7564423ee06826de193717aa5b0 Mon Sep 17 00:00:00 2001 From: Eshan Ramesh Date: Tue, 19 May 2020 16:29:58 -0400 Subject: [PATCH 05/11] make black happy --- jrnl/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jrnl/util.py b/jrnl/util.py index ba46c3da7..945710e9a 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -266,5 +266,5 @@ def split_title(text): if not sep: sep = SENTENCE_SPLITTER.search(text) if not sep: - return "",text + return "", text return text[: sep.end()].strip(), text[sep.end() :].strip() From 8f39b121987e625c980bbb89cf33afdd13af9daa Mon Sep 17 00:00:00 2001 From: Eshan Ramesh Date: Tue, 19 May 2020 16:36:13 -0400 Subject: [PATCH 06/11] make it lstrip not strip --- jrnl/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jrnl/util.py b/jrnl/util.py index 945710e9a..189f1cf51 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -262,7 +262,7 @@ def slugify(string): def split_title(text): """Splits the first sentence off from a text.""" - sep = SENTENCE_SPLITTER_ONLY_NEWLINE.search(text.strip()) + sep = SENTENCE_SPLITTER_ONLY_NEWLINE.search(text.lstrip()) if not sep: sep = SENTENCE_SPLITTER.search(text) if not sep: From d2b4ae995198b660778cad01ffb7511b241150b3 Mon Sep 17 00:00:00 2001 From: Eshan Ramesh Date: Tue, 19 May 2020 17:14:46 -0400 Subject: [PATCH 07/11] fix title-body order for the last time --- jrnl/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jrnl/util.py b/jrnl/util.py index 189f1cf51..6e01087cc 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -266,5 +266,5 @@ def split_title(text): if not sep: sep = SENTENCE_SPLITTER.search(text) if not sep: - return "", text + return text,"" return text[: sep.end()].strip(), text[sep.end() :].strip() From d5a09bd6d71ac74de6142a539b89715018d419b6 Mon Sep 17 00:00:00 2001 From: Eshan Ramesh Date: Tue, 19 May 2020 17:25:20 -0400 Subject: [PATCH 08/11] make black happy again --- jrnl/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jrnl/util.py b/jrnl/util.py index 6e01087cc..3cc325b02 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -266,5 +266,5 @@ def split_title(text): if not sep: sep = SENTENCE_SPLITTER.search(text) if not sep: - return text,"" + return text, "" return text[: sep.end()].strip(), text[sep.end() :].strip() From 6b1bc963e0b02304f3aef2e6732b8e7427ba11d8 Mon Sep 17 00:00:00 2001 From: Eshan Ramesh Date: Sun, 24 May 2020 09:53:11 -0400 Subject: [PATCH 09/11] added test --- features/core.feature | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/features/core.feature b/features/core.feature index df2144943..707f21757 100644 --- a/features/core.feature +++ b/features/core.feature @@ -26,6 +26,12 @@ 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: 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." @@ -39,6 +45,8 @@ Feature: Basic reading and writing to a journal When we open the editor and enter nothing Then we should see the message "[Nothing saved to file]" + + Scenario: Writing an empty entry from the command line Given we use the config "basic.yaml" When we run "jrnl" and enter nothing From 1d3a0fa3cf8e01711cf303b44fd7c9834bd0a819 Mon Sep 17 00:00:00 2001 From: Eshan Ramesh Date: Sun, 24 May 2020 09:57:44 -0400 Subject: [PATCH 10/11] second test for single line entry with punctuation --- features/core.feature | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/features/core.feature b/features/core.feature index 707f21757..c4479610d 100644 --- a/features/core.feature +++ b/features/core.feature @@ -32,6 +32,12 @@ Feature: Basic reading and writing to a journal 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." From b8442cf173fb7924339f4632822922d7014c5522 Mon Sep 17 00:00:00 2001 From: Eshan Ramesh Date: Sun, 24 May 2020 10:06:01 -0400 Subject: [PATCH 11/11] delete extra blank lines --- features/core.feature | 2 -- 1 file changed, 2 deletions(-) diff --git a/features/core.feature b/features/core.feature index c4479610d..8faef24da 100644 --- a/features/core.feature +++ b/features/core.feature @@ -51,8 +51,6 @@ Feature: Basic reading and writing to a journal When we open the editor and enter nothing Then we should see the message "[Nothing saved to file]" - - Scenario: Writing an empty entry from the command line Given we use the config "basic.yaml" When we run "jrnl" and enter nothing