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')
|
raw = raw.replace('\\n ', '\n').replace('\\n', '\n')
|
||||||
starred = False
|
starred = False
|
||||||
# Split raw text into title and body
|
# Split raw text into title and body
|
||||||
title_end = len(raw)
|
sep = re.search("[\n!?.]+", raw)
|
||||||
for separator in ["\n", ". ", "? ", "! "]:
|
title, body = (raw[:sep.end()], raw[sep.end():]) if sep else (raw, "")
|
||||||
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()
|
|
||||||
starred = False
|
starred = False
|
||||||
if not date:
|
if not date:
|
||||||
if title.find(":") > 0:
|
if title.find(":") > 0:
|
||||||
|
@ -338,15 +333,13 @@ class DayOne(Journal):
|
||||||
timezone = pytz.timezone(util.get_local_timezone())
|
timezone = pytz.timezone(util.get_local_timezone())
|
||||||
date = dict_entry['Creation Date']
|
date = dict_entry['Creation Date']
|
||||||
date = date + timezone.utcoffset(date)
|
date = date + timezone.utcoffset(date)
|
||||||
entry = self.new_entry(raw=dict_entry['Entry Text'], date=date, sort=False)
|
raw = dict_entry['Entry Text']
|
||||||
entry.starred = dict_entry["Starred"]
|
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.uuid = dict_entry["UUID"]
|
||||||
entry.tags = dict_entry.get("Tags", [])
|
entry.tags = dict_entry.get("Tags", [])
|
||||||
# We're using new_entry to create the Entry object, which adds the entry
|
self.entries.append(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
|
|
||||||
|
|
||||||
def write(self):
|
def write(self):
|
||||||
"""Writes only the entries that have been modified into plist files."""
|
"""Writes only the entries that have been modified into plist files."""
|
||||||
|
|
|
@ -148,11 +148,10 @@ def run(manual_args=None):
|
||||||
else:
|
else:
|
||||||
journal = Journal.Journal(journal_name, **config)
|
journal = Journal.Journal(journal_name, **config)
|
||||||
|
|
||||||
|
# How to quit writing?
|
||||||
if "win32" in sys.platform:
|
if "win32" in sys.platform:
|
||||||
# for Windows systems
|
|
||||||
_exit_multiline_code = "on a blank line, press Ctrl+Z and then Enter"
|
_exit_multiline_code = "on a blank line, press Ctrl+Z and then Enter"
|
||||||
else:
|
else:
|
||||||
# for *nix systems (and others?)
|
|
||||||
_exit_multiline_code = "press Ctrl+D"
|
_exit_multiline_code = "press Ctrl+D"
|
||||||
|
|
||||||
if mode_compose and not args.text:
|
if mode_compose and not args.text:
|
||||||
|
|
Loading…
Add table
Reference in a new issue