mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 04:58:32 +02:00
Progress towards proper tag colorization and body formatting
This commit is contained in:
parent
95b23d433c
commit
77472261de
2 changed files with 11 additions and 7 deletions
|
@ -51,7 +51,8 @@ class Entry:
|
|||
|
||||
@staticmethod
|
||||
def tag_regex(tagsymbols):
|
||||
pattern = r'(?:^|\s)([{tags}][-+*#/\w]+)'.format(tags=tagsymbols)
|
||||
# pattern = r'(?:^|\s)([{tags}][-+*#/\w]+)'.format(tags=tagsymbols)
|
||||
pattern = r'(?<!\S)([{tags}][-+*#/\w]+)'.format(tags=tagsymbols)
|
||||
return re.compile(pattern, re.UNICODE)
|
||||
|
||||
def _parse_tags(self):
|
||||
|
|
15
jrnl/util.py
15
jrnl/util.py
|
@ -228,8 +228,8 @@ def highlight_tags_with_background_color(entry, text, color, bold=False):
|
|||
:rtype: List of tuples
|
||||
:returns [(colorized_str, original_str)]"""
|
||||
for fragment in fragments:
|
||||
for part in fragment.strip().split(" "):
|
||||
part = part.strip()
|
||||
for part in fragment.lstrip().split(" "):
|
||||
# part = part.strip()
|
||||
if part and part[0] not in config['tagsymbols']:
|
||||
yield (colorize(part, color, bold), part)
|
||||
elif part:
|
||||
|
@ -240,7 +240,7 @@ def highlight_tags_with_background_color(entry, text, color, bold=False):
|
|||
if entry.journal.search_tags:
|
||||
text_fragments = []
|
||||
for tag in entry.search_tags:
|
||||
text_fragments.append(re.split(re.compile(re.escape(tag), re.IGNORECASE),
|
||||
text_fragments.extend(re.split(re.compile(re.escape(tag), re.IGNORECASE),
|
||||
text,
|
||||
flags=re.UNICODE))
|
||||
else:
|
||||
|
@ -248,19 +248,22 @@ def highlight_tags_with_background_color(entry, text, color, bold=False):
|
|||
|
||||
final_text = ""
|
||||
previous_piece = ""
|
||||
# [print("FRAG: '" + repr(frag) + "'") for frag in text_fragments]
|
||||
for colorized_piece, piece in colorized_text_generator(text_fragments):
|
||||
# If it's punctuation and the previous word was a tag, add it directly after the tag.
|
||||
# TODO: This logic seems flawed...
|
||||
if piece in punctuation and previous_piece[0] in config['tagsymbols']:
|
||||
final_text = final_text.lstrip() + colorized_piece
|
||||
# print("PUNCT, POST TAG: '" + colorized_piece + "'")
|
||||
final_text += colorized_piece
|
||||
else:
|
||||
# Otherwise just append it.
|
||||
# print("NOT PUNCT OR NOT POST TAG: '" + colorized_piece + "'")
|
||||
final_text += " " + colorized_piece
|
||||
final_text = final_text.lstrip()
|
||||
|
||||
previous_piece = piece
|
||||
|
||||
return final_text
|
||||
# print("DONE")
|
||||
return final_text.lstrip()
|
||||
else:
|
||||
return text
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue