mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-18 03:58:32 +02:00
Titles will be highlighted as well
This commit is contained in:
parent
511952e203
commit
1e6364400d
3 changed files with 17 additions and 4 deletions
|
@ -22,6 +22,12 @@ class Entry:
|
||||||
pattern = r'(?u)\s([{tags}][-+*#/\w]+)'.format(tags=tagsymbols)
|
pattern = r'(?u)\s([{tags}][-+*#/\w]+)'.format(tags=tagsymbols)
|
||||||
return re.compile( pattern, re.UNICODE )
|
return re.compile( pattern, re.UNICODE )
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def title_regex(self):
|
||||||
|
pattern = r'^(([^|]|[^\s])[^\n]*)'
|
||||||
|
pattern = r'^20.*'
|
||||||
|
return re.compile( pattern, re.UNICODE|re.MULTILINE )
|
||||||
|
|
||||||
def parse_tags(self):
|
def parse_tags(self):
|
||||||
fulltext = " " + " ".join([self.title, self.body]).lower()
|
fulltext = " " + " ".join([self.title, self.body]).lower()
|
||||||
tagsymbols = self.journal.config['tagsymbols']
|
tagsymbols = self.journal.config['tagsymbols']
|
||||||
|
|
|
@ -162,11 +162,14 @@ class Journal(object):
|
||||||
for tag in self.search_tags:
|
for tag in self.search_tags:
|
||||||
tagre = re.compile(re.escape(tag), re.IGNORECASE)
|
tagre = re.compile(re.escape(tag), re.IGNORECASE)
|
||||||
pp = re.sub(tagre,
|
pp = re.sub(tagre,
|
||||||
lambda match: util.colorize(match.group(0)),
|
lambda match: util.colorize_tags(match.group(0)),
|
||||||
pp, re.UNICODE)
|
pp, re.UNICODE)
|
||||||
else:
|
else:
|
||||||
pp = re.sub( Entry.Entry.tag_regex(self.config['tagsymbols']),
|
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)
|
pp)
|
||||||
return pp
|
return pp
|
||||||
|
|
||||||
|
|
|
@ -138,10 +138,14 @@ def get_text_from_editor(config, template=""):
|
||||||
prompt('[Nothing saved to file]')
|
prompt('[Nothing saved to file]')
|
||||||
return raw
|
return raw
|
||||||
|
|
||||||
def colorize(string):
|
def colorize_tags(string):
|
||||||
"""Returns the string wrapped in cyan ANSI escape"""
|
"""Returns the tag string wrapped in cyan ANSI escape"""
|
||||||
return u"\033[36m{}\033[39m".format(string)
|
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):
|
def slugify(string):
|
||||||
"""Slugifies a string.
|
"""Slugifies a string.
|
||||||
Based on public domain code from https://github.com/zacharyvoase/slugify
|
Based on public domain code from https://github.com/zacharyvoase/slugify
|
||||||
|
|
Loading…
Add table
Reference in a new issue