From 7ab969dcfbdc8ecde9a4ceb5f3340bc50ea2bf9a Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Mon, 24 Mar 2014 10:48:51 -0700 Subject: [PATCH 1/2] Fixes white spaces at the beginning of lines, fixes #134 --- jrnl/Entry.py | 24 ++++++++++++------------ jrnl/Journal.py | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/jrnl/Entry.py b/jrnl/Entry.py index d4d3bb6d..37db507c 100644 --- a/jrnl/Entry.py +++ b/jrnl/Entry.py @@ -5,12 +5,13 @@ import re import textwrap from datetime import datetime + class Entry: 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.title = title.strip("\n ") - self.body = body.strip("\n ") + self.title = title.rstrip("\n ") + self.body = body.rstrip("\n ") self.tags = self.parse_tags() self.starred = starred self.modified = False @@ -27,12 +28,11 @@ class Entry: title = date_str + " " + self.title if self.starred: title += " *" - body = self.body.strip() return u"{title}{sep}{body}\n".format( title=title, sep="\n" if self.body else "", - body=body + body=self.body ) def pprint(self, short=False): @@ -47,11 +47,11 @@ class Entry: initial_indent="| ", subsequent_indent="| ", drop_whitespace=False) - for line in self.body.strip().splitlines() + for line in self.body.rstrip().splitlines() ]) else: title = date_str + " " + self.title - body = self.body.strip() + body = self.body # 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) @@ -71,7 +71,7 @@ class Entry: def __eq__(self, other): if not isinstance(other, Entry) \ 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.starred != other.starred: return False @@ -82,8 +82,8 @@ class Entry: def to_dict(self): return { - 'title': self.title.strip(), - 'body': self.body.strip(), + 'title': self.title, + 'body': self.body, 'date': self.date.strftime("%Y-%m-%d"), 'time': self.date.strftime("%H:%M"), 'starred': self.starred @@ -91,8 +91,8 @@ class Entry: def to_md(self): date_str = self.date.strftime(self.journal.config['timeformat']) - body_wrapper = "\n\n" if self.body.strip() else "" - body = body_wrapper + self.body.strip() + body_wrapper = "\n\n" if self.body else "" + body = body_wrapper + self.body space = "\n" md_head = "###" diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 56802929..d1ebc1d0 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -123,9 +123,9 @@ class Journal(object): current_entry = None for line in journal_txt.splitlines(): + line = line.rstrip() try: # try to parse line as date => new entry begins - line = line.strip() new_date = datetime.strptime(line[:date_length], self.config['timeformat']) # parsing successful => save old entry and create new one @@ -280,7 +280,7 @@ class Journal(object): raw = raw.replace('\\n ', '\n').replace('\\n', '\n') starred = False # 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, "") starred = False if not date: @@ -388,7 +388,7 @@ class DayOne(Journal): for line in edited.splitlines(): # try to parse line as UUID => new entry begins - line = line.strip() + line = line.rstrip() m = re.match("# *([a-f0-9]+) *$", line.lower()) if m: if current_entry: From b9cb740f69e2c5a8fcbd6d7a6df5ef750ad2e78d Mon Sep 17 00:00:00 2001 From: Manuel Ebert Date: Mon, 24 Mar 2014 10:48:57 -0700 Subject: [PATCH 2/2] Changelog & version bump --- CHANGELOG.md | 1 + jrnl/__init__.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f7d38c30..7f9260a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Changelog ### 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.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) diff --git a/jrnl/__init__.py b/jrnl/__init__.py index aba1837f..82ff0f1d 100644 --- a/jrnl/__init__.py +++ b/jrnl/__init__.py @@ -8,7 +8,7 @@ jrnl is a simple journal application for your command line. from __future__ import absolute_import __title__ = 'jrnl' -__version__ = '1.7.13' +__version__ = '1.7.14' __author__ = 'Manuel Ebert' __license__ = 'MIT License' __copyright__ = 'Copyright 2013 - 2014 Manuel Ebert'