diff --git a/app/web/components/markdown/index.tsx b/app/web/components/markdown/index.tsx index 5671886..dfc25a8 100644 --- a/app/web/components/markdown/index.tsx +++ b/app/web/components/markdown/index.tsx @@ -13,9 +13,12 @@ import { getScrollOffsets, type Offsets } from "./scroll.ts"; const MARKDOWN_CONTAINER_ID = "markdown-container-id"; const MARKDOWN_ELEMENT_ID = "markdown-element-id"; +const IMAGE_PREFIX = "/__github_preview__/image/"; + const pantsdown = new Pantsdown({ renderer: { - relativeImageUrlPrefix: "/__github_preview__/image/", + relativeImageUrlPrefix: IMAGE_PREFIX, + absoluteImageUrlPrefix: IMAGE_PREFIX, detailsTagDefaultOpen: true, }, }); @@ -67,6 +70,11 @@ export const Markdown = ({ className }: { className: string }) => { const text = message.lines.join("\n"); const markdown = fileExt === "md" ? text : "```" + (fileExt ?? "") + `\n${text}`; + const path = message.currentPath.slice(0, message.currentPath.lastIndexOf("/") + 1); + pantsdown.setConfig({ + renderer: { relativeImageUrlPrefix: IMAGE_PREFIX + path }, + }); + const { html, javascript } = pantsdown.parse(markdown); // We create a tempElement so we can post-process html before actually diff --git a/bun.lock b/bun.lock index 36ca7c2..f6f576c 100644 --- a/bun.lock +++ b/bun.lock @@ -12,7 +12,7 @@ "isbinaryfile": "6.0.0", "mermaid": "^11.15.0", "opener": "^1.5.2", - "pantsdown": "2.2.4", + "pantsdown": "2.2.6", "react": "^19.2.6", "react-dom": "^19.2.6", "reconnecting-websocket": "^4.4.0", @@ -1296,7 +1296,7 @@ "package-manager-detector": ["package-manager-detector@1.6.0", "", {}, "sha512-61A5ThoTiDG/C8s8UMZwSorAGwMJ0ERVGj2OjoW5pAalsNOg15+iQiPzrLJ4jhZ1HJzmC2PIHT2oEiH3R5fzNA=="], - "pantsdown": ["pantsdown@2.2.4", "", { "dependencies": { "github-slugger": "^2.0.0", "highlight.js": "^11.11.1", "katex": "^0.17.0" } }, "sha512-B+LJIpWIxMVQqYmBEEW3zfgWGVgGAvIXHesBP6dXJ8v8NouxPSe4Ci0KqeTBftff5mxAhp4PMdOQkFFXsRGZWg=="], + "pantsdown": ["pantsdown@2.2.6", "", { "dependencies": { "github-slugger": "^2.0.0", "highlight.js": "^11.11.1", "katex": "^0.17.0" } }, "sha512-sknLbX0aztlPuyYcKKoNqDTDKCBQJQEKYckfP77P052Gu19gZmh+M9zKNjMwo9umaP0+aOMG3T8mayUJEqY7Qw=="], "parent-module": ["parent-module@1.0.1", "", { "dependencies": { "callsites": "^3.0.0" } }, "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g=="], diff --git a/docs/FEATURES.md b/docs/FEATURES.md index 652fbd6..6cd3693 100644 --- a/docs/FEATURES.md +++ b/docs/FEATURES.md @@ -50,6 +50,10 @@ https://github.com/wallpants/github-preview.nvim/assets/47203170/a3b03aac-2cd9-4 Relative image sources (example: `![image](./docs/github.svg)`) are resolved and rendered if found. +Images outside of the root of the workspace will not be resolved. + +If using _Single-file mode_, images at the same level as the file or deeper can be resolved, but images in parent directories will not be resolved. + ## 📌 Single-file mode When the plugin starts, it attempts to find a `.git` directory to identify a repository root. diff --git a/package.json b/package.json index 7ea8dda..033fa58 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,7 @@ "isbinaryfile": "6.0.0", "mermaid": "^11.15.0", "opener": "^1.5.2", - "pantsdown": "2.2.4", + "pantsdown": "2.2.6", "react": "^19.2.6", "react-dom": "^19.2.6", "reconnecting-websocket": "^4.4.0",