// 预防 XSS 攻击的安全转义函数
function escapeHTML(str) {
    return str.replace(/[&<>"']/g, function(match) {
        switch(match) {
            case '&': return '&amp;';
            case '<': return '&lt;';
            case '>': return '&gt;';
            case '"': return '&quot;';
            case "'": return '&#39;';
            default: return match;
        }
    });
}
 
// 转义正则特殊字符
export function escapeRegExp(string: string) {
    return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
}
 
// 关键词高亮
const regex = new RegExp(escapeRegExp(escapeHTML(keyword)), 'gi');
str = str.replaceAll(regex, match => `<span class=${styles.highlight}>${match}</span>`);