* 设置主题观察器
()
| 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 | * 更新主题 |
no test coverage detected