diff --git a/jrnl/util.py b/jrnl/util.py index 67052836..30ae80a6 100644 --- a/jrnl/util.py +++ b/jrnl/util.py @@ -215,7 +215,7 @@ def colorize(string, color, bold=False): def highlight_tags_maintain_background_color(entry, text, color, bold=False): """ Takes a string and colorizes the tags in it based upon the config value for - color.tags, while colorizing the rest of the text based on color. + color.tags, while colorizing the rest of the text based on `color`. :param entry: Entry object, for access to journal config :param text: Text to be colorized :param color: Color for non-tag text, passed to colorize() @@ -225,29 +225,26 @@ def highlight_tags_maintain_background_color(entry, text, color, bold=False): config = entry.journal.config if config['highlight']: # highlight tags if entry.journal.search_tags: + search_texts = [] for tag in entry.search_tags: - text_split = re.split(re.compile(re.escape(tag), re.IGNORECASE), - text, - flags=re.UNICODE) - text = [colorize(part.strip(), - color, - bold) - if len(part) > 0 and part[0] not in config['tagsymbols'] - else colorize(part.strip(), - config['colors']['tags'], - not bold) - for part in text_split] + search_texts.append(re.split(re.compile(re.escape(tag), re.IGNORECASE), + text, + flags=re.UNICODE)) else: - text_split = re.split(entry.tag_regex(config['tagsymbols']), text) - text = [colorize(part.strip(), - color, - bold) - if len(part) > 0 and part[0] not in config['tagsymbols'] - else colorize(part.strip(), - config['colors']['tags'], - not bold) - for part in text_split] - return " ".join(text) + search_texts = re.split(entry.tag_regex(config['tagsymbols']), text) + + # TODO: Condense this all into a list comprehension once the broken regression test is fixed. + pretty_printed_entries = [] + for text in search_texts: + pretty_printed_entries.append(" ".join([colorize(part.strip(), + color, + bold) + if len(part) > 0 and part[0] not in config['tagsymbols'] + else colorize(part.strip(), + config['colors']['tags'], + not bold) + for part in text.split()])) + return " ".join(pretty_printed_entries) def slugify(string):