liamcripwell commited on
Commit
c37b0d6
1 Parent(s): 9357e9c

use whitespace instead of space

Browse files
Files changed (1) hide show
  1. app.py +2 -2
app.py CHANGED
@@ -58,9 +58,9 @@ def highlight_words(input_text, json_output):
58
  if path_key not in color_map:
59
  color_map[path_key] = next(colors)
60
  color = color_map[path_key]
61
- # highlighted_text = highlighted_text.replace(f" {value}", f" <span style='background-color: {color};'>{unquote(f'{value}')}</span>")
62
 
63
- pattern = rf"(?<=[ \n\t]){re.escape(value)}(?=[ \n\t\.\,\?\:\;])"
 
64
  replacement = f"<span style='background-color: {color};'>{unquote(value)}</span>"
65
  highlighted_text = re.sub(pattern, replacement, highlighted_text, flags=re.IGNORECASE)
66
 
 
58
  if path_key not in color_map:
59
  color_map[path_key] = next(colors)
60
  color = color_map[path_key]
 
61
 
62
+ escaped_value = re.escape(value).replace(r'\ ', r'\s+') # escape value and replace spaces with \s+
63
+ pattern = rf"(?<=[ \n\t]){escaped_value}(?=[ \n\t\.\,\?\:\;])"
64
  replacement = f"<span style='background-color: {color};'>{unquote(value)}</span>"
65
  highlighted_text = re.sub(pattern, replacement, highlighted_text, flags=re.IGNORECASE)
66