mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-12 01:18:31 +02:00
Merge pull request #644 from wren/escape-dates-GH-631
#631 Escape data in square brackets
This commit is contained in:
commit
a6044b65bc
3 changed files with 28 additions and 8 deletions
|
@ -1,3 +1,13 @@
|
||||||
2010-06-10 15:00 A life without chocolate is like a bad analogy.
|
2010-06-10 15:00 A life without chocolate is like a bad analogy.
|
||||||
|
|
||||||
2013-06-10 15:40 He said "[this] is the best time to be alive".
|
2013-06-10 15:40 He said "[this] is the best time to be alive".
|
||||||
|
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent malesuada
|
||||||
|
quis est ac dignissim. Aliquam dignissim rutrum pretium. Phasellus pellentesque
|
||||||
|
augue et venenatis facilisis.
|
||||||
|
|
||||||
|
[2019-08-03 12:55] Some chat log or something
|
||||||
|
|
||||||
|
Suspendisse potenti. Sed dignissim sed nisl eu consequat. Aenean ante ex,
|
||||||
|
elementum ut interdum et, mattis eget lacus. In commodo nulla nec tellus
|
||||||
|
placerat, sed ultricies metus bibendum. Duis eget venenatis erat. In at dolor
|
||||||
|
dui.
|
||||||
|
|
|
@ -43,15 +43,16 @@ Feature: Zapped bugs should stay dead.
|
||||||
| Hope to get a lot of traffic.
|
| Hope to get a lot of traffic.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Scenario: Upgrade and parse journals with square brackets
|
Scenario: Upgrade and parse journals with square brackets
|
||||||
Given we use the config "upgrade_from_195.json"
|
Given we use the config "upgrade_from_195.json"
|
||||||
When we run "jrnl -2" and enter "Y"
|
When we run "jrnl -9" and enter "Y"
|
||||||
Then the output should contain
|
Then the output should contain
|
||||||
"""
|
"""
|
||||||
2010-06-10 15:00 A life without chocolate is like a bad analogy.
|
2010-06-10 15:00 A life without chocolate is like a bad analogy.
|
||||||
|
|
||||||
2013-06-10 15:40 He said "[this] is the best time to be alive".
|
2013-06-10 15:40 He said "[this] is the best time to be alive".
|
||||||
"""
|
"""
|
||||||
|
Then the journal should have 2 entries
|
||||||
|
|
||||||
Scenario: Integers in square brackets should not be read as dates
|
Scenario: Integers in square brackets should not be read as dates
|
||||||
Given we use the config "brackets.yaml"
|
Given we use the config "brackets.yaml"
|
||||||
|
|
|
@ -118,7 +118,6 @@ class Journal(object):
|
||||||
last_entry_pos = match.end()
|
last_entry_pos = match.end()
|
||||||
entries.append(Entry.Entry(self, date=new_date))
|
entries.append(Entry.Entry(self, date=new_date))
|
||||||
|
|
||||||
|
|
||||||
# If no entries were found, treat all the existing text as an entry made now
|
# If no entries were found, treat all the existing text as an entry made now
|
||||||
if not entries:
|
if not entries:
|
||||||
entries.append(Entry.Entry(self, date=time.parse("now")))
|
entries.append(Entry.Entry(self, date=time.parse("now")))
|
||||||
|
@ -218,7 +217,11 @@ class Journal(object):
|
||||||
if not date:
|
if not date:
|
||||||
colon_pos = first_line.find(": ")
|
colon_pos = first_line.find(": ")
|
||||||
if colon_pos > 0:
|
if colon_pos > 0:
|
||||||
date = time.parse(raw[:colon_pos], default_hour=self.config['default_hour'], default_minute=self.config['default_minute'])
|
date = time.parse(
|
||||||
|
raw[:colon_pos],
|
||||||
|
default_hour=self.config['default_hour'],
|
||||||
|
default_minute=self.config['default_minute']
|
||||||
|
)
|
||||||
if date: # Parsed successfully, strip that from the raw text
|
if date: # Parsed successfully, strip that from the raw text
|
||||||
starred = raw[:colon_pos].strip().endswith("*")
|
starred = raw[:colon_pos].strip().endswith("*")
|
||||||
raw = raw[colon_pos + 1:].strip()
|
raw = raw[colon_pos + 1:].strip()
|
||||||
|
@ -280,6 +283,7 @@ class LegacyJournal(Journal):
|
||||||
# Initialise our current entry
|
# Initialise our current entry
|
||||||
entries = []
|
entries = []
|
||||||
current_entry = None
|
current_entry = None
|
||||||
|
new_date_format_regex = re.compile(r'(^\[[^\]]+\].*?$)')
|
||||||
for line in journal_txt.splitlines():
|
for line in journal_txt.splitlines():
|
||||||
line = line.rstrip()
|
line = line.rstrip()
|
||||||
try:
|
try:
|
||||||
|
@ -299,7 +303,9 @@ class LegacyJournal(Journal):
|
||||||
current_entry = Entry.Entry(self, date=new_date, text=line[date_length + 1:], starred=starred)
|
current_entry = Entry.Entry(self, date=new_date, text=line[date_length + 1:], starred=starred)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# Happens when we can't parse the start of the line as an date.
|
# Happens when we can't parse the start of the line as an date.
|
||||||
# In this case, just append line to our body.
|
# In this case, just append line to our body (after some
|
||||||
|
# escaping for the new format).
|
||||||
|
line = new_date_format_regex.sub(r' \1', line)
|
||||||
if current_entry:
|
if current_entry:
|
||||||
current_entry.text += line + u"\n"
|
current_entry.text += line + u"\n"
|
||||||
|
|
||||||
|
@ -325,7 +331,10 @@ def open_journal(name, config, legacy=False):
|
||||||
from . import DayOneJournal
|
from . import DayOneJournal
|
||||||
return DayOneJournal.DayOne(**config).open()
|
return DayOneJournal.DayOne(**config).open()
|
||||||
else:
|
else:
|
||||||
util.prompt(u"[Error: {0} is a directory, but doesn't seem to be a DayOne journal either.".format(config['journal']))
|
util.prompt(
|
||||||
|
u"[Error: {0} is a directory, but doesn't seem to be a DayOne journal either.".format(config['journal'])
|
||||||
|
)
|
||||||
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not config['encrypt']:
|
if not config['encrypt']:
|
||||||
|
|
Loading…
Add table
Reference in a new issue