(file: TFile)
| 77 | }; |
| 78 | |
| 79 | async loadFile(file: TFile) { |
| 80 | const htmlString = await this.plugin.app.vault.read(file); |
| 81 | const iframe = document.createElement("iframe"); |
| 82 | iframe.width = "100%"; |
| 83 | iframe.height = "100%"; |
| 84 | iframe.srcdoc = htmlString; |
| 85 | this.contentEl.empty(); |
| 86 | this.contentEl.appendChild(iframe); |
| 87 | iframe.style.pointerEvents = "none"; |
| 88 | iframe.addEventListener( |
| 89 | "load", |
| 90 | (evt) => { |
| 91 | iframe.style.pointerEvents = "auto"; |
| 92 | iframe.contentDocument |
| 93 | ?.querySelector("html") |
| 94 | .setAttribute("style", "width: 100%; height: 100%"); |
| 95 | const title = iframe.contentDocument.querySelector("title"); |
| 96 | if (title) { |
| 97 | this.leaf.tabHeaderInnerTitleEl.innerText = title.innerText; |
| 98 | //@ts-ignore |
| 99 | this.leaf.view.titleEl = title.innerText; |
| 100 | const headerEl = this.leaf.view.headerEl; |
| 101 | if (headerEl) { |
| 102 | //@ts-ignore |
| 103 | headerEl.querySelector(".view-header-title").innerText = |
| 104 | title.innerText; |
| 105 | } |
| 106 | } |
| 107 | const divs = iframe.contentDocument.querySelectorAll("div"); |
| 108 | divs.forEach((div: HTMLElement) => { |
| 109 | // If the href attribute ends with .md |
| 110 | const style = div.style; |
| 111 | if ( |
| 112 | style.backgroundImage && |
| 113 | style.backgroundImage.startsWith("url") |
| 114 | ) { |
| 115 | const bi = style.backgroundImage.slice(4, -1).replace(/"/g, ""); |
| 116 | if (bi.startsWith("http")) return; |
| 117 | if (bi.startsWith("app")) return; |
| 118 | div.style.backgroundImage = `url('${this.plugin.superstate.ui.getUIPath( |
| 119 | this.plugin.superstate.spaceManager.resolvePath(bi, file.path) |
| 120 | )}')`; |
| 121 | } |
| 122 | }); |
| 123 | |
| 124 | const links = iframe.contentDocument.querySelectorAll("a"); |
| 125 | links.forEach((link: Element) => { |
| 126 | if (!link.getAttribute("href").startsWith("http")) { |
| 127 | link.addEventListener("click", (event) => { |
| 128 | event.preventDefault(); |
| 129 | this.openPathInViewer(link.getAttribute("href")); |
| 130 | }); |
| 131 | } |
| 132 | }); |
| 133 | const navItems = |
| 134 | iframe.contentDocument.querySelectorAll(".nav-contents"); |
| 135 | navItems.forEach((link: Element) => { |
| 136 | if (!link.getAttribute("data-path")?.startsWith("http")) { |
no test coverage detected