mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 21:18:32 +02:00
Fixed the 'spaces after tags directly next to punctuation' bug
Broke processing of tags next to any punctuation at all
This commit is contained in:
parent
41fb8d45eb
commit
e9bfe4dcac
1 changed files with 19 additions and 6 deletions
25
jrnl/util.py
25
jrnl/util.py
|
@ -17,6 +17,7 @@ import subprocess
|
||||||
import codecs
|
import codecs
|
||||||
import unicodedata
|
import unicodedata
|
||||||
import shlex
|
import shlex
|
||||||
|
from string import punctuation
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -222,14 +223,17 @@ def highlight_tags_with_background_color(entry, text, color, bold=False):
|
||||||
"""
|
"""
|
||||||
def colorized_text_generator(fragments):
|
def colorized_text_generator(fragments):
|
||||||
"""Efficiently generate colorized tags / text from text fragments.
|
"""Efficiently generate colorized tags / text from text fragments.
|
||||||
:param fragments: List of strings representing parts of entry (tag or word)."""
|
Taken from @shobrook. Thanks, buddy :)
|
||||||
# Taken from @shobrook. Thanks, buddy :)
|
:param fragments: List of strings representing parts of entry (tag or word).
|
||||||
|
:rtype: List of tuples
|
||||||
|
:returns [(colorized_str, original_str)]"""
|
||||||
for fragment in fragments:
|
for fragment in fragments:
|
||||||
for part in fragment.strip().split(" "):
|
for part in fragment.strip().split(" "):
|
||||||
|
part = part.strip()
|
||||||
if part and part[0] not in config['tagsymbols']:
|
if part and part[0] not in config['tagsymbols']:
|
||||||
yield colorize(part.strip(), color, bold)
|
yield (colorize(part, color, bold), part)
|
||||||
else:
|
elif part:
|
||||||
yield colorize(part.strip(), config['colors']['tags'], not bold)
|
yield (colorize(part, config['colors']['tags'], not bold), part)
|
||||||
|
|
||||||
config = entry.journal.config
|
config = entry.journal.config
|
||||||
if config['highlight']: # highlight tags
|
if config['highlight']: # highlight tags
|
||||||
|
@ -242,8 +246,17 @@ def highlight_tags_with_background_color(entry, text, color, bold=False):
|
||||||
else:
|
else:
|
||||||
text_fragments = re.split(entry.tag_regex(config['tagsymbols']), text)
|
text_fragments = re.split(entry.tag_regex(config['tagsymbols']), text)
|
||||||
|
|
||||||
return " ".join(colorized_text_generator(text_fragments))
|
final_text = ""
|
||||||
|
previous_piece = ""
|
||||||
|
for colorized_piece, piece in colorized_text_generator(text_fragments):
|
||||||
|
if piece in punctuation and previous_piece[0] not in config['tagsymbols']:
|
||||||
|
final_text = final_text.strip() + colorized_piece
|
||||||
|
else:
|
||||||
|
final_text += colorized_piece + " "
|
||||||
|
|
||||||
|
previous_piece = piece
|
||||||
|
|
||||||
|
return final_text
|
||||||
else:
|
else:
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue