Skip to content

Commit ec31e28

Browse files
committed
fix(markdown): fix relative asserts path
1 parent 952a905 commit ec31e28

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/@vuepress/markdown/__tests__/plugins/assetsPlugin.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const source = [
1515
'![empty]()',
1616
'![alias](@alias/foo.png)',
1717
'![~alias](~@alias/foo.png)',
18+
'![中国](./中国.png)',
19+
'![finish](./100%.png)',
1820
].join('\n\n')
1921

2022
describe('@vuepress/markdown > plugins > assetsPlugin', () => {
@@ -40,6 +42,8 @@ describe('@vuepress/markdown > plugins > assetsPlugin', () => {
4042
'<img src="" alt="empty">',
4143
'<img src="@alias/foo.png" alt="alias">',
4244
'<img src="~@alias/foo.png" alt="~alias">',
45+
'<img src="@source/sub/中国.png" alt="中国">',
46+
'<img src="@source/sub/100%.png" alt="finish">',
4347
]
4448
.map((item) => `<p>${item}</p>`)
4549
.join('\n') + '\n'
@@ -70,6 +74,8 @@ describe('@vuepress/markdown > plugins > assetsPlugin', () => {
7074
'<img src="" alt="empty">',
7175
'<img src="@alias/foo.png" alt="alias">',
7276
'<img src="~@alias/foo.png" alt="~alias">',
77+
'<img src="@foo/sub/中国.png" alt="中国">',
78+
'<img src="@foo/sub/100%.png" alt="finish">',
7379
]
7480
.map((item) => `<p>${item}</p>`)
7581
.join('\n') + '\n'
@@ -96,6 +102,8 @@ describe('@vuepress/markdown > plugins > assetsPlugin', () => {
96102
'<img src="" alt="empty">',
97103
'<img src="@alias/foo.png" alt="alias">',
98104
'<img src="~@alias/foo.png" alt="~alias">',
105+
'<img src="./%E4%B8%AD%E5%9B%BD.png" alt="中国">',
106+
'<img src="./100%25.png" alt="finish">',
99107
]
100108
.map((item) => `<p>${item}</p>`)
101109
.join('\n') + '\n'

packages/@vuepress/markdown/src/plugins/assetsPlugin.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { PluginWithOptions } from 'markdown-it'
2+
import { decode } from 'mdurl'
23
import { path } from '@vuepress/utils'
34
import type { MarkdownEnv } from '../types'
45

@@ -29,7 +30,8 @@ export const assetsPlugin: PluginWithOptions<AssetsPluginOptions> = (
2930
// add `@source` alias to the link
3031
const resolvedLink = `${relativePathPrefix}/${path.join(
3132
path.dirname(env.filePathRelative),
32-
link
33+
// decode link to the origin one so that bundler can find the file correctly
34+
decode(link)
3335
)}`
3436

3537
// replace the original link with absolute path

0 commit comments

Comments
 (0)