MCPcopy Create free account
hub / github.com/Feather-2/Burner-X / processNode

Function processNode

js/processing/formula_post_processor.js:218–243  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

216
217 // 递归处理所有文本节点
218 function processNode(node) {
219 // 跳过已经渲染过的 KaTeX 元素
220 if (node.classList && (node.classList.contains('katex') || node.classList.contains('katex-inline') || node.classList.contains('katex-block'))) {
221 return;
222 }
223
224 // 跳过 script、style、code 等标签
225 if (node.tagName && /^(SCRIPT|STYLE|CODE|PRE)$/.test(node.tagName)) {
226 return;
227 }
228
229 // 处理文本节点
230 if (node.nodeType === Node.TEXT_NODE) {
231 const text = node.textContent;
232
233 // 检查是否包含公式标记
234 if (text.includes('$')) {
235 processTextNode(node);
236 }
237 }
238 // 递归处理子节点
239 else if (node.childNodes) {
240 // 转换为数组避免在遍历时修改 DOM 导致问题
241 Array.from(node.childNodes).forEach(processNode);
242 }
243 }
244
245 /**
246 * 处理单个文本节点,将其中的公式替换为渲染后的 HTML

Callers 2

collectFormulasMethod · 0.85
processFormulasInElementFunction · 0.85

Calls 1

processTextNodeFunction · 0.85

Tested by

no test coverage detected