Skip to content

Commit

Permalink
Fix dropping local media in an MDX file
Browse files Browse the repository at this point in the history
This was using `URL.canParse`, which isn’t available in the Node.js
version used by VSCode. This failed silently.  This is fixed by using
strict parse mode from `vscode-uri`.

Closes #322
  • Loading branch information
remcohaszing committed Nov 27, 2023
1 parent dacb61d commit 64b0652
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/fix-drop-provider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'volar-mdx'
---

Fix dropping local images in an MDX file.
30 changes: 15 additions & 15 deletions packages/vscode-mdx/src/document-drop-edit-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ export const documentDropEditProvider = {
const content = []

for (const line of uris) {
if (!URL.canParse(line)) {
try {
const uri = Uri.parse(line, true)
const value =
uri.scheme === document.uri.scheme
? path.posix.relative(document.uri.path, uri.path)
: line

content.push(
toMarkdown(
imageExtensions.has(path.posix.extname(uri.path))
? {type: 'image', url: value}
: {type: 'text', value}
).trim()
)
} catch {
continue
}

const uri = Uri.parse(line)
const value =
uri.scheme === document.uri.scheme
? path.posix.relative(document.uri.path, uri.path)
: line

content.push(
toMarkdown(
imageExtensions.has(path.posix.extname(uri.path))
? {type: 'image', url: value}
: {type: 'text', value}
).trim()
)
}

return {
Expand Down

0 comments on commit 64b0652

Please sign in to comment.