| 422 | |
| 423 | // 替换 svg 标签中的一些大小写敏感的词(html 不区分大小写,但 svg 标签区分大小写) |
| 424 | function replaceSensitiveWords(text: string): string { |
| 425 | // 1. 使用正则匹配大小写敏感词 |
| 426 | // 2. 逐个替换为正确大小写形式 |
| 427 | return text.replace(/viewbox|preserveaspectratio|clippathunits|gradienttransform|patterncontentunits|lineargradient|clippath/gi, (match) => { |
| 428 | switch (match.toLowerCase()) { |
| 429 | case 'viewbox': |
| 430 | return 'viewBox'; |
| 431 | case 'preserveaspectratio': |
| 432 | return 'preserveAspectRatio'; |
| 433 | case 'clippathunits': |
| 434 | return 'clipPathUnits'; |
| 435 | case 'gradienttransform': |
| 436 | return 'gradientTransform'; |
| 437 | case 'patterncontentunits': |
| 438 | return 'patternContentUnits'; |
| 439 | case 'lineargradient': |
| 440 | return 'linearGradient'; |
| 441 | case 'clippath': |
| 442 | return 'clipPath'; |
| 443 | default: |
| 444 | return match; |
| 445 | } |
| 446 | }); |
| 447 | } |
| 448 | |
| 449 | // 移除特定样式 |
| 450 | export function checkAndRemoveStyle(node: any, styleProperty: any) { |