mirror of
https://github.com/owncast/owncast.git
synced 2024-11-28 11:09:01 +03:00
highlighting: make case-insensitive, support unicode (#3137)
* highlighting: make case-insensitive, support unicode * highlighting: also highlight simplified/normalized form * highlighting: use MDN-recommended escape pattern
This commit is contained in:
parent
80ffd28551
commit
5c07e3ced6
1 changed files with 12 additions and 1 deletions
|
@ -19,7 +19,18 @@ export class ChatMessageHighlightMatcher extends Matcher {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = str.match(highlightString);
|
const escapedString = highlightString
|
||||||
|
.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||||
|
.replace(/\s/g, '\\s');
|
||||||
|
|
||||||
|
const normalizedString = escapedString.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
|
||||||
|
|
||||||
|
let highlightRegex = escapedString;
|
||||||
|
if (escapedString !== normalizedString) {
|
||||||
|
highlightRegex = `(?:${escapedString})|(?:${normalizedString})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = str.match(new RegExp(highlightRegex, 'ui'));
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue