Vitepress VS Code resolve absolute path to docs/ in markdown

348 Views Asked by At

I am using VitePress (fot that matter it might as well be VuePress) in Visual Studio Code.

In markdown files you can normally write links relative to any other markdown document.

You can also write absolute links which VitePress resolves (by default) to the /docs/ folder in your project.

For example, this markdown link [Foo](/foo.md) resolves to this document in the project /docs/foo.md.

I could also write it as as a relative link. For example if I am in /docs/bar/baz.md I can write [Foo](../foo.md).

All good until then. Both links work for VitePress.

The issue is with the links as VS Code recognizes them. Normally you can CTRL+click on a link in the editor and VS Code opens that file in a new editor tab. However, VS Code, for obvious reasons, only resolves correctly the relative paths, because the absolute paths are resolved to <project>/ instead of <project>/docs/.

Question: Is there a way to tell VS Code that all absolute links should be resolved to the /docs/ folder?

I am thinking of something like this (however this doesn't work):

// /docs/jsconfig.json
{
    "compilerOptions": {
        "baseUrl": "./" // try to get md files to resolve absolute paths from docs/ like [](/orgchart.md), so far no luck
    }
}
1

There are 1 best solutions below

0
On

Ok, the solution lies within the concept of monorepos and a vs code workspace.

I followed this medium article for instructions.

Basically, create a /docs/.vscode/settings.json file, and replace the settings.json file in the root .vscode folder for .vscode/project.code-workspace file.

Instantly vs code recognized the configuration and offered a button with text "open workspace" (relaunching the project window).