Merge pull request #261 from kneufeld/master

using a common tag regex for searching and highlighting
This commit is contained in:
Manuel Ebert 2014-09-02 13:07:33 -07:00
commit 53958cf328
2 changed files with 10 additions and 4 deletions

View file

@ -16,9 +16,15 @@ class Entry:
self.starred = starred
self.modified = False
@staticmethod
def tag_regex(tagsymbols):
pattern = r'(?u)\s([{tags}][-+*#/\w]+)'.format(tags=tagsymbols)
return re.compile( pattern, re.UNICODE )
def parse_tags(self):
fulltext = " " + " ".join([self.title, self.body]).lower()
tags = re.findall(r'(?u)\s([{tags}][-+*#/\w]+)'.format(tags=self.journal.config['tagsymbols']), fulltext, re.UNICODE)
tagsymbols = self.journal.config['tagsymbols']
tags = re.findall( Entry.tag_regex(tagsymbols), fulltext )
self.tags = tags
return set(tags)

View file

@ -165,7 +165,7 @@ class Journal(object):
lambda match: util.colorize(match.group(0)),
pp, re.UNICODE)
else:
pp = re.sub(r"(?u)([{tags}]\w+)".format(tags=self.config['tagsymbols']),
pp = re.sub( Entry.Entry.tag_regex(self.config['tagsymbols']),
lambda match: util.colorize(match.group(0)),
pp)
return pp