From e7f92a32c211390b79406ad98b494bed178ecb63 Mon Sep 17 00:00:00 2001 From: Sprax Lines Date: Mon, 3 Oct 2016 01:05:16 -0400 Subject: [PATCH] Config extra chars to be allowed inside tags. --- jrnl/Entry.py | 11 ++++++++--- jrnl/Journal.py | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/jrnl/Entry.py b/jrnl/Entry.py index 2a2a03b2..c920cce6 100755 --- a/jrnl/Entry.py +++ b/jrnl/Entry.py @@ -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) diff --git a/jrnl/Journal.py b/jrnl/Journal.py index 92a6774f..d17472f3 100644 --- a/jrnl/Journal.py +++ b/jrnl/Journal.py @@ -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