Local images in Markdown LightVirtualFile

Answered

In my plugin code I'm opening a Markdown file in-memory using `LightVirtualFile` and setting the file language to `MarkdownLanguage.INSTANCE`. I use the following code to open the file for editing:

FileEditorManager manager = FileEditorManager
.getInstance(Objects.requireNonNull(anActionEvent.getProject()));
manager.openFile(markdownFile, true, true);

I'm noticing though, that links to local files in the in-memory Markdown file never resolve:

I'm positive that this is the correct file path to the image, as the link successfully resolves when I use this same link in a scratch Markdown file. I'm thinking the local link resolution problem is with the Markdown file being in-memory. Because it's in-memory, the Markdown plugin is unable to access files on local disk? That would seem to make sense to me. If this is not a correct assumption, does anyone know what could be causing this issue. And if this is the correct assumption, is there a workaround or trick to access local disk files from an in-memory LightVirtualFile?

1 comment
Comment actions Permalink

Hi,

You are correct with your assumptions. The Markdown file created as a LightVirtualFile cannot access the image because it doesn't exist in the same VirtualFileSystem.

The workaround would be to create a temporary regular Markdown file on your file system (e.g., in the system temp directory).

1

Please sign in to leave a comment.