fix(news-details): prevent keyword acronyms from highlighting unrelated words

This commit is contained in:
2026-08-10 16:50:23 +02:00
parent 79dad5dfb0
commit e5284a79c9
@@ -206,8 +206,15 @@ export class NewsDetailComponent implements OnInit {
const color = keywordColorMap.get(kw.toLowerCase());
if (!color) return;
const kwHtml = this.escapeHtml(kw);
const escaped = this.escapeRegex(kwHtml);
const before = '(?<![\\w\\u00C0-\\u024F])';
const acronymLike =
kw.length <= 3 ||
(kw === kw.toUpperCase() && kw !== kw.toLowerCase());
const re = new RegExp(
`(${this.escapeRegex(kwHtml)}[\\w\\u00C0-\\u024F]*)`,
acronymLike
? `${before}(${escaped})(?![\\w\\u00C0-\\u024F])`
: `${before}(${escaped}[\\w\\u00C0-\\u024F]*)`,
'gi',
);
html = html.replace(