()
| 262 | } |
| 263 | |
| 264 | onload(): void { |
| 265 | if (this.sourcePath) { |
| 266 | rememberSourcePath(this.containerEl, this.sourcePath); |
| 267 | } |
| 268 | |
| 269 | const processEmbeds = () => { |
| 270 | const embeds = this.containerEl.querySelectorAll(".file-embed"); |
| 271 | for (const embed of Array.from(embeds)) { |
| 272 | const embedEl = embed as HTMLElement; |
| 273 | const effectiveSourcePath = |
| 274 | this.sourcePath || |
| 275 | resolveSourcePathForEmbed(embedEl, this.plugin); |
| 276 | if (!effectiveSourcePath) continue; |
| 277 | |
| 278 | rememberSourcePath(embedEl, effectiveSourcePath); |
| 279 | scheduleProcessCodeEmbed(embedEl, this.plugin, effectiveSourcePath); |
| 280 | } |
| 281 | }; |
| 282 | |
| 283 | processEmbeds(); |
| 284 | |
| 285 | this.observer = new MutationObserver((mutations) => { |
| 286 | let shouldRescan = false; |
| 287 | |
| 288 | for (const mutation of mutations) { |
| 289 | for (const node of Array.from(mutation.addedNodes)) { |
| 290 | if (node.nodeType !== 1) continue; |
| 291 | const elem = node as Element; |
| 292 | if (elem.classList.contains("file-embed") || elem.querySelector(".file-embed")) { |
| 293 | shouldRescan = true; |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | if (shouldRescan) break; |
| 299 | } |
| 300 | |
| 301 | if (shouldRescan) { |
| 302 | processEmbeds(); |
| 303 | } |
| 304 | }); |
| 305 | |
| 306 | this.observer.observe(this.containerEl, { childList: true, subtree: true }); |
| 307 | } |
| 308 | |
| 309 | onunload(): void { |
| 310 | if (this.observer) { |
nothing calls this directly
no test coverage detected