MCPcopy Create free account
hub / github.com/Auto-Plugin/milkup / setupThemeObserver

Method setupThemeObserver

src/core/nodeviews/code-block.ts:1327–1349  ·  view source on GitHub ↗

* 设置主题观察器

()

Source from the content-addressed store, hash-verified

1325 * 设置主题观察器
1326 */
1327 private setupThemeObserver(): void {
1328 const htmlElement = document.documentElement;
1329
1330 this.themeObserver = new MutationObserver((mutations) => {
1331 for (const mutation of mutations) {
1332 if (mutation.type === "attributes" && mutation.attributeName === "class") {
1333 const isDark = detectDarkTheme();
1334 this.updateTheme(isDark);
1335 // 更新 Mermaid 预览
1336 if (this.node.attrs.language === "mermaid" && this.mermaidPreview) {
1337 // 先清空旧内容,避免新旧 SVG 层叠
1338 this.mermaidPreview.innerHTML = "";
1339 this.createMermaidPreview(this.cm.state.doc.toString());
1340 }
1341 }
1342 }
1343 });
1344
1345 this.themeObserver.observe(htmlElement, {
1346 attributes: true,
1347 attributeFilter: ["class"],
1348 });
1349 }
1350
1351 /**
1352 * 更新主题

Callers 1

constructorMethod · 0.95

Calls 3

updateThemeMethod · 0.95
createMermaidPreviewMethod · 0.95
detectDarkThemeFunction · 0.85

Tested by

no test coverage detected