mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-06-28 21:46:13 +02:00
using a common tag regex for searching and highlighting
This commit is contained in:
parent
5bfb82cf90
commit
2f1894c765
2 changed files with 10 additions and 4 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue