mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
Cleaner parsing
This commit is contained in:
parent
e4bc0794f1
commit
ca6b16a5a1
2 changed files with 8 additions and 16 deletions
|
@ -285,13 +285,8 @@ class Journal(object):
|
|||
raw = raw.replace('\\n ', '\n').replace('\\n', '\n')
|
||||
starred = False
|
||||
# Split raw text into title and body
|
||||
title_end = len(raw)
|
||||
for separator in ["\n", ". ", "? ", "! "]:
|
||||
sep_pos = raw.find(separator)
|
||||
if 1 < sep_pos < title_end:
|
||||
title_end = sep_pos
|
||||
title = raw[:title_end+1]
|
||||
body = raw[title_end+1:].strip()
|
||||
sep = re.search("[\n!?.]+", raw)
|
||||
title, body = (raw[:sep.end()], raw[sep.end():]) if sep else (raw, "")
|
||||
starred = False
|
||||
if not date:
|
||||
if title.find(":") > 0:
|
||||
|
@ -338,15 +333,13 @@ class DayOne(Journal):
|
|||
timezone = pytz.timezone(util.get_local_timezone())
|
||||
date = dict_entry['Creation Date']
|
||||
date = date + timezone.utcoffset(date)
|
||||
entry = self.new_entry(raw=dict_entry['Entry Text'], date=date, sort=False)
|
||||
entry.starred = dict_entry["Starred"]
|
||||
raw = dict_entry['Entry Text']
|
||||
sep = re.search("[\n!?.]+", raw)
|
||||
title, body = (raw[:sep.end()], raw[sep.end():]) if sep else (raw, "")
|
||||
entry = Entry.Entry(self, date, title, body, starred=dict_entry["Starred"])
|
||||
entry.uuid = dict_entry["UUID"]
|
||||
entry.tags = dict_entry.get("Tags", [])
|
||||
# We're using new_entry to create the Entry object, which adds the entry
|
||||
# to self.entries already. However, in the original Journal.__init__, this
|
||||
# method is expected to return a list of newly created entries, which is why
|
||||
# we're returning the obvious.
|
||||
return self.entries
|
||||
self.entries.append(entry)
|
||||
|
||||
def write(self):
|
||||
"""Writes only the entries that have been modified into plist files."""
|
||||
|
|
|
@ -148,11 +148,10 @@ def run(manual_args=None):
|
|||
else:
|
||||
journal = Journal.Journal(journal_name, **config)
|
||||
|
||||
# How to quit writing?
|
||||
if "win32" in sys.platform:
|
||||
# for Windows systems
|
||||
_exit_multiline_code = "on a blank line, press Ctrl+Z and then Enter"
|
||||
else:
|
||||
# for *nix systems (and others?)
|
||||
_exit_multiline_code = "press Ctrl+D"
|
||||
|
||||
if mode_compose and not args.text:
|
||||
|
|
Loading…
Add table
Reference in a new issue