Config extra chars to be allowed inside tags.

This commit is contained in:
Sprax Lines 2016-10-03 01:05:16 -04:00
parent df200fa6f9
commit e7f92a32c2
2 changed files with 11 additions and 4 deletions

View file

@ -18,14 +18,19 @@ class Entry:
self.modified = False
@staticmethod
def tag_regex(tagsymbols):
pattern = r'(?u)\s([{tags}][-+*#&/\w]+)'.format(tags=tagsymbols)
def tag_regex(tagsymbols, tag_extras):
"""Returns the user-configurable pattern to match tags, where:
tagsymbols mark the beginning of a tag, and
tag_extras are any additional characters to be allowed inside tags
(besides those already in the pattern below, namely [-+*#/\w])."""
pattern = r'(?u)\s([{tags}][-+*#/{chars}\w]+)'.format(tags=tagsymbols, chars=tag_extras)
return re.compile( pattern, re.UNICODE )
def parse_tags(self):
fulltext = " " + " ".join([self.title, self.body]).lower()
tagsymbols = self.journal.config['tagsymbols']
tags = re.findall( Entry.tag_regex(tagsymbols), fulltext )
tag_extras = self.journal.config['tag_extras']
tags = re.findall( Entry.tag_regex(tagsymbols, tag_extras), fulltext )
self.tags = tags
return set(tags)

View file

@ -27,6 +27,7 @@ class Journal(object):
'default_minute': 0,
'timeformat': "%Y-%m-%d %H:%M",
'tagsymbols': '@',
'tag_extras': '$^&',
'highlight': True,
'linewrap': 80,
}
@ -165,7 +166,8 @@ class Journal(object):
lambda match: util.colorize(match.group(0)),
pp, re.UNICODE)
else:
pp = re.sub( Entry.Entry.tag_regex(self.config['tagsymbols']),
pp = re.sub( Entry.Entry.tag_regex(self.config['tagsymbols'],
self.config['tag_extras']),
lambda match: util.colorize(match.group(0)),
pp)
return pp