Skip to content

[Feature request] Add img_alias_limit #1646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
LincZero opened this issue Apr 28, 2025 · 3 comments · May be fixed by #1647
Open

[Feature request] Add img_alias_limit #1646

LincZero opened this issue Apr 28, 2025 · 3 comments · May be fixed by #1647

Comments

@LincZero
Copy link

LincZero commented Apr 28, 2025

Clear and concise description of the problem

Leading factors

Due to the alias mechanism of vuepress: https://vuejs.press/zh/guide/assets.html

vuepress extends the behavior of <img src="urls not beginning with ./ or/", overwriting the syntax of md and causing syntax conflicts. That is, only looking at md and not vuepress, this way of writing is completely legal and compliant. And this will cause some problems.

Environment and Demand

On this basis, many blog posts by writers who do not use vuepress do not notice this point. They might have been using other file builders (such as gitbook, cookbook, vitepress, mdbook) before this. Or perhaps they haven't started using the document builder, but have already written quite a lot of md content.

In these environments (other md document builders and markdown local editors), the situation where img src is not prefixed with ./ or / exists in large numbers.

A typical case is that I often deploy some online documents, and these documents might be written by others. They might not have used the document builder before or used other document builders.

Then in the past, during the deployment process (following the open-source license), I modified the original document a lot due to compilation errors (yes, I don't want to do this anymore, and it's very difficult for me to convince others to accept this kind of PR where I added ./ because the original content is completely legal), and found that this writing style is widespread (I have encountered five document repositories because this one cannot be compiled and needs to be modified).

As for why they don't use it ![](), might be because you want to add attr/class/attr/style/size, etc. Perhaps it is because it is used in some html fragments (such as <detail>)

Suggested solution

I can make a PR if the FR is approved.

Consider adding the function to:https://ecosystem.vuejs.press/plugins/markdown/markdown-image.html

Note that I have retained the function of using aliases when '@' is used as a prefix, and this will not reduce the original function. It is said that previously, the alias of vitepress had to start with ~, so this situation will not occur

code: (straight-ahead)

Image

Alternative

No response

Additional context

The code for handling the corresponding logic in vuepress

@LincZero
Copy link
Author

LincZero commented Apr 28, 2025

Additional: Another tool that can help reduce errors when migrating from other document builders to vuepress or adding vuepress builders from existing documents.

img_not_found plugin: It is allowed to modify the invalid image into a 404 image and only use the warning prompt instead of the compilation error.

(code TODO: unpolished, the situation of the public folder was not considered)

Image

@Mister-Hope
Copy link
Member

I think you should add this function to core, while adding a new option called markdown.image

@Mister-Hope Mister-Hope transferred this issue from vuepress/ecosystem Apr 29, 2025
@LincZero LincZero linked a pull request Apr 29, 2025 that will close this issue
6 tasks
@LincZero
Copy link
Author

LincZero commented Apr 29, 2025

Document supplement after the completion of this PR #1647 :

(I'll write the document here for now. Once the PR is completed, I'll copy it over to the document side.)

Option

(add to: https://vuepress.github.io/zh/reference/config.html#markdown-assets)

How to disable/limit url aliases、Usage

(add to: https://vuepress.github.io/zh/guide/assets.html#base-helper)

.vuepress/config.ts

const userConfig: UserConfig = {
  markdown: {
      assets: {
        aliasSupport: '@-perfix'
      }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants