Commit 4c587f33 authored by Zéfling's avatar Zéfling 🎨
Browse files

Fix highlight the value in a search

parent 2def90c1
......@@ -101,6 +101,7 @@
display: flex;
flex: 1;
flex-direction: column-reverse;
justify-content: flex-end;
}
.tweet {
......
......@@ -200,12 +200,21 @@ export class TweetsService {
const match = tweet.html_text.match(new RegExp(Utils.formatToUnicodePattern(value), 'gi'));
if (match) {
const copy = Utils.jsonCopy<Tweet>(tweet);
// highlight value except in tags
match.forEach(
(m: string) => {
copy.html_text = copy.html_text.replace(
new RegExp(Utils.protectPattern(m), 'gi'),
`<span class="key">${m}</span>`
);
const testInTag = new RegExp(`([<]?[^<>]*${Utils.protectPattern(m)}[^<>]*[>]?)`, 'gi');
tweet.html_text.match(testInTag).forEach(frag => {
if (!frag.startsWith('<')) {
copy.html_text = copy.html_text.replace(
frag,
frag.replace(
new RegExp(Utils.protectPattern(m), 'gi'),
`<span class="key">${m}</span>`
)
);
}
});
}
);
result.push(copy);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment