INNER CODE UNIT · TypeScript
extractFormulasFromOriginalDom
RyanYipeng/SyncCaster · apps/extension/src/content-scripts/index.ts:58
function extractFormulasFromOriginalDom(): Map<string, { tex: string; isDisplay: boolean }> {
const formulaMap = new Map<string, { tex: string; isDisplay: boolean }>();
const serializer = new XMLSerializer();
const processed = new WeakSet<Element>();
let index = 0;
const hostname = window.location.hostname;
const isZhihu = hostname.includes('zhihu.com');
// 知乎专用公式提取
if (isZhihu) {
// 知乎使用 data-tex 属性存储 LaTeX
document.querySelectorAll('[data-tex]').forEach((node) => {
if (processed.has(node)) return;
processed.add(node);
const tex = node.getAttribute('data-tex')?.trim();
if (tex) {
const id = 'formula-' + (index++);