core
core copied to clipboard
[Feature request] Add img_alias_limit
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)
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
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)
I think you should add this function to core, while adding a new option called markdown.image
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'
}
}
}
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.
T
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.
T
@meteorlxy plz review this
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.
T
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.
T_T
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.
T
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.
T
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.
Is the author still quite busy?
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.
T
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.
T
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.
T
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.
T
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.
T