core icon indicating copy to clipboard operation
core copied to clipboard

[Feature request] Add img_alias_limit

Open LincZero opened this issue 7 months ago • 10 comments

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

  • https://github.com/vuepress/core/blob/a78ee55b4dabbaad7cd3ec9e2a0c7bf1eaa15c87/packages/markdown/src/markdown.ts#L84
    • https://github.com/vuepress/core/blob/a78ee55b4dabbaad7cd3ec9e2a0c7bf1eaa15c87/packages/markdown/src/plugins/assetsPlugin/assetsPlugin.ts#L40

LincZero avatar Apr 28 '25 10:04 LincZero

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

LincZero avatar Apr 28 '25 11:04 LincZero

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

Mister-Hope avatar Apr 29 '25 12:04 Mister-Hope

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'
      }
  }
}

LincZero avatar Apr 29 '25 16:04 LincZero

This issue is marked as stale because it has not had recent activity. Issues marked with stale will be closed if they have no activity within 7 days.

github-actions[bot] avatar May 16 '25 01:05 github-actions[bot]

T

LincZero avatar May 16 '25 01:05 LincZero

This issue is marked as stale because it has not had recent activity. Issues marked with stale will be closed if they have no activity within 7 days.

github-actions[bot] avatar Jun 01 '25 01:06 github-actions[bot]

T

LincZero avatar Jun 01 '25 10:06 LincZero

@meteorlxy plz review this

Mister-Hope avatar Jun 01 '25 10:06 Mister-Hope

This issue is marked as stale because it has not had recent activity. Issues marked with stale will be closed if they have no activity within 7 days.

github-actions[bot] avatar Jun 17 '25 01:06 github-actions[bot]

T

LincZero avatar Jun 17 '25 05:06 LincZero

This issue is marked as stale because it has not had recent activity. Issues marked with stale will be closed if they have no activity within 7 days.

github-actions[bot] avatar Jul 03 '25 01:07 github-actions[bot]

T_T

LincZero avatar Jul 03 '25 01:07 LincZero

This issue is marked as stale because it has not had recent activity. Issues marked with stale will be closed if they have no activity within 7 days.

github-actions[bot] avatar Jul 19 '25 01:07 github-actions[bot]

T

LincZero avatar Jul 19 '25 03:07 LincZero

This issue is marked as stale because it has not had recent activity. Issues marked with stale will be closed if they have no activity within 7 days.

github-actions[bot] avatar Aug 04 '25 01:08 github-actions[bot]

T

LincZero avatar Aug 05 '25 14:08 LincZero

This issue is marked as stale because it has not had recent activity. Issues marked with stale will be closed if they have no activity within 7 days.

github-actions[bot] avatar Aug 21 '25 01:08 github-actions[bot]

Is the author still quite busy?

LincZero avatar Aug 21 '25 01:08 LincZero

This issue is marked as stale because it has not had recent activity. Issues marked with stale will be closed if they have no activity within 7 days.

github-actions[bot] avatar Sep 06 '25 01:09 github-actions[bot]

T

LincZero avatar Sep 06 '25 03:09 LincZero

This issue is marked as stale because it has not had recent activity. Issues marked with stale will be closed if they have no activity within 7 days.

github-actions[bot] avatar Sep 22 '25 01:09 github-actions[bot]

T

LincZero avatar Sep 22 '25 01:09 LincZero

This issue is marked as stale because it has not had recent activity. Issues marked with stale will be closed if they have no activity within 7 days.

github-actions[bot] avatar Oct 08 '25 01:10 github-actions[bot]

T

LincZero avatar Oct 08 '25 04:10 LincZero

This issue is marked as stale because it has not had recent activity. Issues marked with stale will be closed if they have no activity within 7 days.

github-actions[bot] avatar Oct 24 '25 01:10 github-actions[bot]

T

LincZero avatar Oct 24 '25 01:10 LincZero

This issue is marked as stale because it has not had recent activity. Issues marked with stale will be closed if they have no activity within 7 days.

github-actions[bot] avatar Nov 09 '25 01:11 github-actions[bot]

T

LincZero avatar Nov 09 '25 12:11 LincZero