vuepress / core

Vue-Powered Static Site Generator
https://vuepress.vuejs.org
MIT License
2.29k stars 926 forks source link

[Feature request] Recognize @source and maybe treat all @ started path as alias with markdown image #1584

Open Mister-Hope opened 3 months ago

Mister-Hope commented 3 months ago

Clear and concise description of the problem

Some people may want to reference image from root, but in our latest changes, the markdown image syntax no longer supports alias.

![](a/b.jpg) is regarded as <img src="./a/b.jpg" /> even if a is a package name or valid alias.

This is more expected as a/b.jpg will be a relative path in most cases instead a path that need to be resolved with bundler.

Also, we provided backwards ability, that in case people want to use alias or package imports, they can use img tag:

<img src="a/b.jpg" /> will be ./b.jpg exports in package a.

But we internally support @source for src folder, and when users want to reference images in projects folder instead of public (in most cases people are using i18n, and a image is placed at root language, and they want to make the link constant in all languages like @source/guide/example.png)

Suggested solution

We'd better check whether a markdown image link is started with @source/ , to avoid a @source/a.jpg being parsed as @source/folder/@source/a.jpg from @source/folder/file.md.

And we may even treat all links started with @ as alias. This is more flexible that allows markdown image be default as relative links but still supports alias.

Alternative

No response

Additional context

No response

Mister-Hope commented 3 months ago

@meteorlxy

Mister-Hope commented 2 months ago

@meteorlxy Reping

meteorlxy commented 2 months ago

@source is an internal shim, cuz we are generating temp files from source files. Ideally we should remove the shim, allowing relative image reference from markdown directly.