| 384 | // 清理可能导致 URI malformed 错误的特殊字符(孤立的 Unicode 代理对) |
| 385 | const textNodesBackup: { node: Text; originalText: string }[] = [] |
| 386 | const cleanProblematicCharacters = (text: string): string => { |
| 387 | // 移除孤立的代理对(会导致 encodeURIComponent 失败) |
| 388 | // 高代理:\uD800-\uDBFF,低代理:\uDC00-\uDFFF |
| 389 | // 有效的代理对应该是 高代理+低代理 的组合 |
| 390 | return text.replace(/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g, '\uFFFD') |
| 391 | } |
| 392 | const walker = document.createTreeWalker(element, NodeFilter.SHOW_TEXT, null) |
| 393 | let textNode: Text | null |
| 394 | while ((textNode = walker.nextNode() as Text | null)) { |