mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-18 12:08:31 +02:00
Config extra chars to be allowed inside tags.
This commit is contained in:
parent
df200fa6f9
commit
e7f92a32c2
2 changed files with 11 additions and 4 deletions
|
@ -18,14 +18,19 @@ class Entry:
|
||||||
self.modified = False
|
self.modified = False
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def tag_regex(tagsymbols):
|
def tag_regex(tagsymbols, tag_extras):
|
||||||
pattern = r'(?u)\s([{tags}][-+*#&/\w]+)'.format(tags=tagsymbols)
|
"""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 )
|
return re.compile( pattern, re.UNICODE )
|
||||||
|
|
||||||
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']
|
||||||
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
|
self.tags = tags
|
||||||
return set(tags)
|
return set(tags)
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@ class Journal(object):
|
||||||
'default_minute': 0,
|
'default_minute': 0,
|
||||||
'timeformat': "%Y-%m-%d %H:%M",
|
'timeformat': "%Y-%m-%d %H:%M",
|
||||||
'tagsymbols': '@',
|
'tagsymbols': '@',
|
||||||
|
'tag_extras': '$^&',
|
||||||
'highlight': True,
|
'highlight': True,
|
||||||
'linewrap': 80,
|
'linewrap': 80,
|
||||||
}
|
}
|
||||||
|
@ -165,7 +166,8 @@ class Journal(object):
|
||||||
lambda match: util.colorize(match.group(0)),
|
lambda match: util.colorize(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'],
|
||||||
|
self.config['tag_extras']),
|
||||||
lambda match: util.colorize(match.group(0)),
|
lambda match: util.colorize(match.group(0)),
|
||||||
pp)
|
pp)
|
||||||
return pp
|
return pp
|
||||||
|
|
Loading…
Add table
Reference in a new issue