mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-10 16:48:31 +02:00
parent
cf7581c0c0
commit
5bb8f9c567
5 changed files with 14 additions and 12 deletions
|
@ -5,6 +5,7 @@ Changelog
|
|||
|
||||
* [New] JSON export exports tags as well.
|
||||
* [Improved] Nicer error message when there is a syntactical error in your config file.
|
||||
* [Improved] Unicode support
|
||||
|
||||
#### 1.0.5
|
||||
|
||||
|
|
|
@ -15,16 +15,16 @@ class Entry:
|
|||
|
||||
def parse_tags(self):
|
||||
fulltext = " ".join([self.title, self.body]).lower()
|
||||
tags = re.findall(r"([%s]\w+)" % self.journal.config['tagsymbols'], fulltext)
|
||||
tags = re.findall(ur'([{}]\w+)'.format(self.journal.config['tagsymbols']), fulltext, re.UNICODE)
|
||||
self.tags = set(tags)
|
||||
|
||||
def __str__(self):
|
||||
def __unicode__(self):
|
||||
"""Returns a string representation of the entry to be written into a journal file."""
|
||||
date_str = self.date.strftime(self.journal.config['timeformat'])
|
||||
title = date_str + " " + self.title
|
||||
body = self.body.strip()
|
||||
|
||||
return "{title}{sep}{body}\n".format(
|
||||
return u"{title}{sep}{body}\n".format(
|
||||
title=title,
|
||||
sep="\n" if self.body else "",
|
||||
body=body
|
||||
|
@ -50,7 +50,7 @@ class Entry:
|
|||
# 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)
|
||||
|
||||
return "{title}{sep}{body}\n".format(
|
||||
return u"{title}{sep}{body}\n".format(
|
||||
title=title,
|
||||
sep="\n" if has_body else "",
|
||||
body=body if has_body else "",
|
||||
|
@ -74,7 +74,7 @@ class Entry:
|
|||
space = "\n"
|
||||
md_head = "###"
|
||||
|
||||
return "{md} {date}, {title} {body} {space}".format(
|
||||
return u"{md} {date}, {title} {body} {space}".format(
|
||||
md=md_head,
|
||||
date=date_str,
|
||||
title=self.title,
|
||||
|
|
|
@ -158,7 +158,7 @@ class Journal(object):
|
|||
entry.parse_tags()
|
||||
return entries
|
||||
|
||||
def __str__(self):
|
||||
def __unicode__(self):
|
||||
"""Prettyprints the journal's entries"""
|
||||
sep = "\n"
|
||||
pp = sep.join([e.pprint() for e in self.entries])
|
||||
|
@ -168,9 +168,9 @@ class Journal(object):
|
|||
tagre = re.compile(re.escape(tag), re.IGNORECASE)
|
||||
pp = re.sub(tagre,
|
||||
lambda match: self._colorize(match.group(0)),
|
||||
pp)
|
||||
pp, re.UNICODE)
|
||||
else:
|
||||
pp = re.sub(r"([%s]\w+)" % self.config['tagsymbols'],
|
||||
pp = re.sub(ur"(?u)([{}]\w+)".format(self.config['tagsymbols']),
|
||||
lambda match: self._colorize(match.group(0)),
|
||||
pp)
|
||||
return pp
|
||||
|
@ -181,7 +181,7 @@ class Journal(object):
|
|||
def write(self, filename=None):
|
||||
"""Dumps the journal into the config file, overwriting it"""
|
||||
filename = filename or self.config['journal']
|
||||
journal = "\n".join([str(e) for e in self.entries])
|
||||
journal = "\n".join([unicode(e) for e in self.entries])
|
||||
if self.config['encrypt']:
|
||||
journal = self._encrypt(journal)
|
||||
with open(filename, 'wb') as journal_file:
|
||||
|
|
|
@ -25,7 +25,7 @@ def to_tag_list(journal):
|
|||
elif min(tag_counts)[0] == 0:
|
||||
tag_counts = filter(lambda x: x[0] > 1, tag_counts)
|
||||
result += '[Removed tags that appear only once.]\n'
|
||||
result += "\n".join("{0:20} : {1}".format(tag, n) for n, tag in sorted(tag_counts, reverse=False))
|
||||
result += "\n".join(u"{0:20} : {1}".format(tag, n) for n, tag in sorted(tag_counts, reverse=False))
|
||||
return result
|
||||
|
||||
def to_json(journal):
|
||||
|
|
|
@ -171,7 +171,8 @@ def cli():
|
|||
# Writing mode
|
||||
if mode_compose:
|
||||
raw = " ".join(args.text).strip()
|
||||
entry = journal.new_entry(raw, args.date)
|
||||
unicode_raw = raw.decode(sys.getfilesystemencoding())
|
||||
entry = journal.new_entry(unicode_raw, args.date)
|
||||
entry.starred = args.star
|
||||
print("[Entry added to {0} journal]".format(journal_name))
|
||||
journal.write()
|
||||
|
@ -183,7 +184,7 @@ def cli():
|
|||
strict=args.strict,
|
||||
short=args.short)
|
||||
journal.limit(args.limit)
|
||||
print(journal)
|
||||
print(unicode(journal))
|
||||
|
||||
# Various export modes
|
||||
elif args.tags:
|
||||
|
|
Loading…
Add table
Reference in a new issue