| 393 | |
| 394 | // 仅译文模式下获取 LLM 应当翻译的标准 HTML |
| 395 | export function LLMStandardHTML(node: any) { |
| 396 | // 1. 初始化空字符串 text |
| 397 | // 2. 遍历子节点 |
| 398 | // 3. 若为文本节点,拼接其文本内容 |
| 399 | // 4. 若为元素节点且在 inlineSet 中,拼接其 outerHTML |
| 400 | // 5. 否则继续递归处理子节点 |
| 401 | let text = ""; |
| 402 | node.childNodes.forEach((child: any) => { |
| 403 | if (child.nodeType === Node.TEXT_NODE) { |
| 404 | text += child.nodeValue; |
| 405 | } else if (child.nodeType === Node.ELEMENT_NODE) { |
| 406 | if (inlineSet.has(child.tagName.toLowerCase())) { |
| 407 | text += child.outerHTML; |
| 408 | } else { |
| 409 | text += LLMStandardHTML(child); |
| 410 | } |
| 411 | } |
| 412 | }); |
| 413 | return text; |
| 414 | } |
| 415 | |
| 416 | export function beautyHTML(text: string): string { |
| 417 | // 1. 先替换 SVG 中的大小写敏感词 |