MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / resolveRenderedImages

Function resolveRenderedImages

src/pages/markdownPreview/index.js:207–245  ·  view source on GitHub ↗
(container, file)

Source from the content-addressed store, hash-verified

205}
206
207async 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
247function createMarkdownPreview(file) {
248 const $page = Page(file.filename);

Callers 1

renderFunction · 0.85

Calls 5

getMarkdownBaseUriFunction · 0.90
isExternalLinkFunction · 0.90
resolveMarkdownTargetFunction · 0.90
fileToObjectUrlFunction · 0.85
addMethod · 0.80

Tested by

no test coverage detected