This commit is contained in:
Florian Baumann 2017-04-16 05:59:38 +00:00 committed by GitHub
commit 3d796b478a
3 changed files with 16 additions and 4 deletions

View file

@ -22,6 +22,11 @@ class Entry:
pattern = r'(?u)\s([{tags}][-+*#/\w]+)'.format(tags=tagsymbols)
return re.compile( pattern, re.UNICODE )
@staticmethod
def title_regex(self):
pattern = r'^20.*'
return re.compile( pattern, re.UNICODE|re.MULTILINE )
def parse_tags(self):
fulltext = " " + " ".join([self.title, self.body]).lower()
tagsymbols = self.journal.config['tagsymbols']

View file

@ -162,11 +162,14 @@ class Journal(object):
for tag in self.search_tags:
tagre = re.compile(re.escape(tag), re.IGNORECASE)
pp = re.sub(tagre,
lambda match: util.colorize(match.group(0)),
lambda match: util.colorize_tags(match.group(0)),
pp, re.UNICODE)
else:
pp = re.sub( Entry.Entry.tag_regex(self.config['tagsymbols']),
lambda match: util.colorize(match.group(0)),
lambda match: util.colorize_tags(match.group(0)),
pp)
pp = re.sub( Entry.Entry.title_regex(self.config['tagsymbols']),
lambda match: util.colorize_titles(match.group(0)),
pp)
return pp

View file

@ -138,10 +138,14 @@ def get_text_from_editor(config, template=""):
prompt('[Nothing saved to file]')
return raw
def colorize(string):
"""Returns the string wrapped in cyan ANSI escape"""
def colorize_tags(string):
"""Returns the tag string wrapped in cyan ANSI escape"""
return u"\033[36m{}\033[39m".format(string)
def colorize_titles(string):
"""Returns the title string wrapped in cyan ANSI escape"""
return u"\033[1m\033[37m{}\033[0m".format(string)
def slugify(string):
"""Slugifies a string.
Based on public domain code from https://github.com/zacharyvoase/slugify