fix html highlight
Browse files- candidates.py +3 -6
candidates.py
CHANGED
|
@@ -74,14 +74,11 @@ def launch_app(df: pd.DataFrame, share_demo: bool = False):
|
|
| 74 |
|
| 75 |
# Function to highlight words from the candidates list
|
| 76 |
def highlight_words(text, candidates, color="yellow"):
|
| 77 |
-
if color == "yellow":
|
| 78 |
-
pattern = r'<mark>\1</mark>'
|
| 79 |
-
else:
|
| 80 |
-
pattern = r'<mark style="background-color:{green};">\1</mark>'
|
| 81 |
-
|
| 82 |
for word in candidates:
|
| 83 |
# Use word boundaries to ensure we only match whole words
|
| 84 |
-
text = re.sub(rf'\b({re.escape(word)})\b', r'
|
|
|
|
|
|
|
| 85 |
return text
|
| 86 |
|
| 87 |
# Highlight words in the 'completion' column
|
|
|
|
| 74 |
|
| 75 |
# Function to highlight words from the candidates list
|
| 76 |
def highlight_words(text, candidates, color="yellow"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
for word in candidates:
|
| 78 |
# Use word boundaries to ensure we only match whole words
|
| 79 |
+
text = re.sub(rf'\b({re.escape(word)})\b', r'<@>\1</@>', text, flags=re.IGNORECASE)
|
| 80 |
+
text = re.sub("<@>",f'<mark style="background-color:{color};">', text)
|
| 81 |
+
text = re.sub("</@>",'</mark>'.format(color=color), text)
|
| 82 |
return text
|
| 83 |
|
| 84 |
# Highlight words in the 'completion' column
|