Skip to content

Commit 64b0652

Browse files
committed
Fix dropping local media in an MDX file
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
1 parent dacb61d commit 64b0652

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

.changeset/fix-drop-provider.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'volar-mdx'
3+
---
4+
5+
Fix dropping local images in an MDX file.

packages/vscode-mdx/src/document-drop-edit-provider.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,23 @@ export const documentDropEditProvider = {
7575
const content = []
7676

7777
for (const line of uris) {
78-
if (!URL.canParse(line)) {
78+
try {
79+
const uri = Uri.parse(line, true)
80+
const value =
81+
uri.scheme === document.uri.scheme
82+
? path.posix.relative(document.uri.path, uri.path)
83+
: line
84+
85+
content.push(
86+
toMarkdown(
87+
imageExtensions.has(path.posix.extname(uri.path))
88+
? {type: 'image', url: value}
89+
: {type: 'text', value}
90+
).trim()
91+
)
92+
} catch {
7993
continue
8094
}
81-
82-
const uri = Uri.parse(line)
83-
const value =
84-
uri.scheme === document.uri.scheme
85-
? path.posix.relative(document.uri.path, uri.path)
86-
: line
87-
88-
content.push(
89-
toMarkdown(
90-
imageExtensions.has(path.posix.extname(uri.path))
91-
? {type: 'image', url: value}
92-
: {type: 'text', value}
93-
).trim()
94-
)
9595
}
9696

9797
return {

0 commit comments

Comments
 (0)