Merge pull request #146 from maebert/fix-whitespaces

Fix whitespaces
This commit is contained in:
Manuel Ebert 2014-03-24 11:07:09 -07:00
commit 4606a4ab6d
4 changed files with 17 additions and 16 deletions

View file

@ -4,6 +4,7 @@ Changelog
### 1.7 (December 22, 2013) ### 1.7 (December 22, 2013)
* __1.7.14__ Fix for trailing whitespaces (eg. when writing markdown code block)
* __1.7.13__ Fix for UTF-8 in DayOne journals * __1.7.13__ Fix for UTF-8 in DayOne journals
* __1.7.12__ Fixes a bug where filtering by tags didn't work for DayOne journals * __1.7.12__ Fixes a bug where filtering by tags didn't work for DayOne journals
* __1.7.11__ `-ls` will list all available journals (Thanks @jtan189) * __1.7.11__ `-ls` will list all available journals (Thanks @jtan189)

View file

@ -5,12 +5,13 @@ import re
import textwrap import textwrap
from datetime import datetime from datetime import datetime
class Entry: class Entry:
def __init__(self, journal, date=None, title="", body="", starred=False): def __init__(self, journal, date=None, title="", body="", starred=False):
self.journal = journal # Reference to journal mainly to access it's config self.journal = journal # Reference to journal mainly to access it's config
self.date = date or datetime.now() self.date = date or datetime.now()
self.title = title.strip("\n ") self.title = title.rstrip("\n ")
self.body = body.strip("\n ") self.body = body.rstrip("\n ")
self.tags = self.parse_tags() self.tags = self.parse_tags()
self.starred = starred self.starred = starred
self.modified = False self.modified = False
@ -27,12 +28,11 @@ class Entry:
title = date_str + " " + self.title title = date_str + " " + self.title
if self.starred: if self.starred:
title += " *" title += " *"
body = self.body.strip()
return u"{title}{sep}{body}\n".format( return u"{title}{sep}{body}\n".format(
title=title, title=title,
sep="\n" if self.body else "", sep="\n" if self.body else "",
body=body body=self.body
) )
def pprint(self, short=False): def pprint(self, short=False):
@ -47,11 +47,11 @@ class Entry:
initial_indent="| ", initial_indent="| ",
subsequent_indent="| ", subsequent_indent="| ",
drop_whitespace=False) drop_whitespace=False)
for line in self.body.strip().splitlines() for line in self.body.rstrip().splitlines()
]) ])
else: else:
title = date_str + " " + self.title title = date_str + " " + self.title
body = self.body.strip() body = self.body
# Suppress bodies that are just blanks and new lines. # Suppress bodies that are just blanks and new lines.
has_body = len(self.body) > 20 or not all(char in (" ", "\n") for char in self.body) has_body = len(self.body) > 20 or not all(char in (" ", "\n") for char in self.body)
@ -71,7 +71,7 @@ class Entry:
def __eq__(self, other): def __eq__(self, other):
if not isinstance(other, Entry) \ if not isinstance(other, Entry) \
or self.title.strip() != other.title.strip() \ or self.title.strip() != other.title.strip() \
or self.body.strip() != other.body.strip() \ or self.body.rstrip() != other.body.rstrip() \
or self.date != other.date \ or self.date != other.date \
or self.starred != other.starred: or self.starred != other.starred:
return False return False
@ -82,8 +82,8 @@ class Entry:
def to_dict(self): def to_dict(self):
return { return {
'title': self.title.strip(), 'title': self.title,
'body': self.body.strip(), 'body': self.body,
'date': self.date.strftime("%Y-%m-%d"), 'date': self.date.strftime("%Y-%m-%d"),
'time': self.date.strftime("%H:%M"), 'time': self.date.strftime("%H:%M"),
'starred': self.starred 'starred': self.starred
@ -91,8 +91,8 @@ class Entry:
def to_md(self): def to_md(self):
date_str = self.date.strftime(self.journal.config['timeformat']) date_str = self.date.strftime(self.journal.config['timeformat'])
body_wrapper = "\n\n" if self.body.strip() else "" body_wrapper = "\n\n" if self.body else ""
body = body_wrapper + self.body.strip() body = body_wrapper + self.body
space = "\n" space = "\n"
md_head = "###" md_head = "###"

View file

@ -123,9 +123,9 @@ class Journal(object):
current_entry = None current_entry = None
for line in journal_txt.splitlines(): for line in journal_txt.splitlines():
line = line.rstrip()
try: try:
# try to parse line as date => new entry begins # try to parse line as date => new entry begins
line = line.strip()
new_date = datetime.strptime(line[:date_length], self.config['timeformat']) new_date = datetime.strptime(line[:date_length], self.config['timeformat'])
# parsing successful => save old entry and create new one # parsing successful => save old entry and create new one
@ -280,7 +280,7 @@ 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
sep = re.search("[\n!?.]+", raw) sep = re.search("\n|[\?.]+", raw)
title, body = (raw[:sep.end()], raw[sep.end():]) if sep else (raw, "") title, body = (raw[:sep.end()], raw[sep.end():]) if sep else (raw, "")
starred = False starred = False
if not date: if not date:
@ -388,7 +388,7 @@ class DayOne(Journal):
for line in edited.splitlines(): for line in edited.splitlines():
# try to parse line as UUID => new entry begins # try to parse line as UUID => new entry begins
line = line.strip() line = line.rstrip()
m = re.match("# *([a-f0-9]+) *$", line.lower()) m = re.match("# *([a-f0-9]+) *$", line.lower())
if m: if m:
if current_entry: if current_entry:

View file

@ -8,7 +8,7 @@ jrnl is a simple journal application for your command line.
from __future__ import absolute_import from __future__ import absolute_import
__title__ = 'jrnl' __title__ = 'jrnl'
__version__ = '1.7.13' __version__ = '1.7.14'
__author__ = 'Manuel Ebert' __author__ = 'Manuel Ebert'
__license__ = 'MIT License' __license__ = 'MIT License'
__copyright__ = 'Copyright 2013 - 2014 Manuel Ebert' __copyright__ = 'Copyright 2013 - 2014 Manuel Ebert'