(container, file)
| 205 | } |
| 206 | |
| 207 | async function resolveRenderedImages(container, file) { |
| 208 | const baseUri = getMarkdownBaseUri(file); |
| 209 | const objectUrls = []; |
| 210 | const images = Array.from(container.querySelectorAll("img[src]")); |
| 211 | |
| 212 | images.forEach((image) => { |
| 213 | const src = image.getAttribute("src"); |
| 214 | if (!src || src.startsWith("data:") || src.startsWith("blob:")) return; |
| 215 | if (src.startsWith("#") || isExternalLink(src)) return; |
| 216 | if (!image.hasAttribute("data-markdown-local-src")) { |
| 217 | image.setAttribute( |
| 218 | "data-markdown-local-src", |
| 219 | resolveMarkdownTarget(src, baseUri), |
| 220 | ); |
| 221 | } |
| 222 | }); |
| 223 | |
| 224 | await Promise.all( |
| 225 | images.map(async (image) => { |
| 226 | const resolvedPath = image.getAttribute("data-markdown-local-src"); |
| 227 | if (!resolvedPath) return; |
| 228 | |
| 229 | try { |
| 230 | const objectUrl = await fileToObjectUrl(resolvedPath); |
| 231 | |
| 232 | image.setAttribute("src", objectUrl); |
| 233 | image.setAttribute("data-source-uri", resolvedPath); |
| 234 | image.setAttribute("loading", "lazy"); |
| 235 | image.setAttribute("decoding", "async"); |
| 236 | image.classList.add("markdown-image"); |
| 237 | objectUrls.push(objectUrl); |
| 238 | } catch (error) { |
| 239 | console.warn("Failed to resolve markdown image:", resolvedPath, error); |
| 240 | } |
| 241 | }), |
| 242 | ); |
| 243 | |
| 244 | return objectUrls; |
| 245 | } |
| 246 | |
| 247 | function createMarkdownPreview(file) { |
| 248 | const $page = Page(file.filename); |
no test coverage detected