(node, indent = '')
| 747 | |
| 748 | // Process all child nodes |
| 749 | const processNode = (node, indent = '') => { |
| 750 | // Skip if not a valid node |
| 751 | if (!node) return; |
| 752 | |
| 753 | // Handle source footnotes (引用上标) |
| 754 | if (node.nodeType === Node.ELEMENT_NODE && node.tagName === 'SOURCE-FOOTNOTE') { |
| 755 | // 如果 sourceIndexMap 为空,表示用户不想导出来源,跳过所有引用上标 |
| 756 | if (sourceIndexMap.size === 0) { |
| 757 | return; |
| 758 | } |
| 759 | const supElement = node.querySelector('sup[data-turn-source-index]'); |
| 760 | if (supElement) { |
| 761 | const turnIndex = parseInt(supElement.getAttribute('data-turn-source-index'), 10); |
| 762 | const sourceInfo = sourceIndexMap.get(turnIndex); |
| 763 | if (sourceInfo) { |
| 764 | // 插入可点击的上标链接 |
| 765 | result += `<sup>[[${sourceInfo.displayIndex}]](#ref-${sourceInfo.displayIndex})</sup>`; |
| 766 | } |
| 767 | // 如果找不到映射,不输出任何内容(可能是来源列表中不存在的索引) |
| 768 | } |
| 769 | return; |
| 770 | } |
| 771 | |
| 772 | // Handle sources-carousel-inline (跳过来源轮播) |
| 773 | if (node.nodeType === Node.ELEMENT_NODE && node.tagName === 'SOURCES-CAROUSEL-INLINE') { |
| 774 | return; // 跳过这个元素 |
| 775 | } |
| 776 | |
| 777 | // Handle response-element wrappers (处理响应元素包装器) |
| 778 | if (node.nodeType === Node.ELEMENT_NODE && node.tagName === 'RESPONSE-ELEMENT') { |
| 779 | node.childNodes.forEach(n => processNode(n, indent)); |
| 780 | return; |
| 781 | } |
| 782 | |
| 783 | // Handle block-level math formulas |
| 784 | if (node.nodeType === Node.ELEMENT_NODE && node.classList && node.classList.contains('math-block')) { |
| 785 | // Priority 1: Use data-math attribute |
| 786 | const dataMath = node.getAttribute('data-math'); |
| 787 | if (dataMath) { |
| 788 | // If in a list, add indent to the markers, but not the formula content |
| 789 | if (indent) { |
| 790 | result += '\n' + indent + '$$\n' + dataMath.trim() + '\n' + indent + '$$\n\n'; |
| 791 | } else { |
| 792 | result += '\n$$\n' + dataMath.trim() + '\n$$\n\n'; |
| 793 | } |
| 794 | return; |
| 795 | } |
| 796 | // Priority 2: Try .math-src element |
| 797 | const mathSrc = node.querySelector('.math-src'); |
| 798 | if (mathSrc && mathSrc.textContent && mathSrc.textContent.trim()) { |
| 799 | if (indent) { |
| 800 | result += '\n' + indent + '$$\n' + mathSrc.textContent.trim() + '\n' + indent + '$$\n\n'; |
| 801 | } else { |
| 802 | result += '\n$$\n' + mathSrc.textContent.trim() + '\n$$\n\n'; |
| 803 | } |
| 804 | return; |
| 805 | } |
| 806 | // Priority 3: Fallback to KaTeX annotation |
no test coverage detected