mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-18 03:58:32 +02:00
Merge 0e340296cc
into 9ffca1a7a6
This commit is contained in:
commit
3d796b478a
3 changed files with 16 additions and 4 deletions
|
@ -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']
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue