mirror of
https://github.com/facebook/docusaurus.git
synced 2025-04-29 18:27:56 +02:00
fix(mdx-loader): allow image paths to be URL encoded (#6792)
This commit is contained in:
parent
1ac41132e3
commit
8a24d56783
10 changed files with 18 additions and 2 deletions
|
@ -8,6 +8,8 @@
|
|||
|
||||

|
||||
|
||||

|
||||
|
||||
 
|
||||
|
||||

|
||||
|
|
BIN
packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/__fixtures__/static2/img2 copy.png
generated
Normal file
BIN
packages/docusaurus-mdx-loader/src/remark/transformImage/__tests__/__fixtures__/static2/img2 copy.png
generated
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
|
@ -27,6 +27,8 @@ exports[`transformImage plugin transform md images to <img /> 1`] = `
|
|||
|
||||
<img loading=\\"lazy\\" alt={\\"img from second static folder\\"} src={require(\\"!<PROJECT_ROOT>/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[contenthash].[ext]&fallback=<PROJECT_ROOT>/node_modules/file-loader/dist/cjs.js!./static2/img2.png\\").default} width=\\"256\\" height=\\"82\\" />
|
||||
|
||||
<img loading=\\"lazy\\" alt={\\"img with URL encoded chars\\"} src={require(\\"!<PROJECT_ROOT>/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[contenthash].[ext]&fallback=<PROJECT_ROOT>/node_modules/file-loader/dist/cjs.js!./static2/img2 copy.png\\").default} width=\\"256\\" height=\\"82\\" />
|
||||
|
||||
<img loading=\\"lazy\\" alt={\\"img\\"} src={require(\\"!<PROJECT_ROOT>/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[contenthash].[ext]&fallback=<PROJECT_ROOT>/node_modules/file-loader/dist/cjs.js!./static/img.png\\").default} title=\\"Title\\" width=\\"200\\" height=\\"200\\" /> <img loading=\\"lazy\\" alt={\\"img\\"} src={require(\\"!<PROJECT_ROOT>/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[contenthash].[ext]&fallback=<PROJECT_ROOT>/node_modules/file-loader/dist/cjs.js!./static/img.png\\").default} width=\\"200\\" height=\\"200\\" />
|
||||
|
||||
<img loading=\\"lazy\\" alt={\\"img with "quotes"\\"} src={require(\\"!<PROJECT_ROOT>/node_modules/url-loader/dist/cjs.js?limit=10000&name=assets/images/[name]-[contenthash].[ext]&fallback=<PROJECT_ROOT>/node_modules/file-loader/dist/cjs.js!./static/img.png\\").default} title=\\"'Quoted' title\\" width=\\"200\\" height=\\"200\\" />
|
||||
|
|
|
@ -121,7 +121,10 @@ async function getImageAbsolutePath(
|
|||
return imageFilePath;
|
||||
}
|
||||
// relative paths are resolved against the source file's folder
|
||||
const imageFilePath = path.join(path.dirname(filePath), imagePath);
|
||||
const imageFilePath = path.join(
|
||||
path.dirname(filePath),
|
||||
decodeURIComponent(imagePath),
|
||||
);
|
||||
await ensureImageFileExist(imageFilePath, filePath);
|
||||
return imageFilePath;
|
||||
}
|
||||
|
|
0
packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/__fixtures__/asset (2).pdf
generated
Normal file
0
packages/docusaurus-mdx-loader/src/remark/transformLinks/__tests__/__fixtures__/asset (2).pdf
generated
Normal file
|
@ -4,6 +4,8 @@
|
|||
|
||||
[asset](./asset.pdf)
|
||||
|
||||
[asset with URL encoded chars](./asset%20%282%29.pdf)
|
||||
|
||||
[asset with hash](./asset.pdf#page=2)
|
||||
|
||||
[asset](asset.pdf 'Title')
|
||||
|
|
|
@ -16,6 +16,8 @@ exports[`transformAsset plugin transform md links to <a /> 1`] = `
|
|||
|
||||
<a target=\\"_blank\\" href={require('!<PROJECT_ROOT>/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[contenthash].[ext]!./asset.pdf').default}>asset</a>
|
||||
|
||||
<a target=\\"_blank\\" href={require('!<PROJECT_ROOT>/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[contenthash].[ext]!./asset (2).pdf').default}>asset with URL encoded chars</a>
|
||||
|
||||
<a target=\\"_blank\\" href={require('!<PROJECT_ROOT>/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[contenthash].[ext]!./asset.pdf').default + '#page=2'}>asset with hash</a>
|
||||
|
||||
<a target=\\"_blank\\" href={require('!<PROJECT_ROOT>/node_modules/file-loader/dist/cjs.js?name=assets/files/[name]-[contenthash].[ext]!./asset.pdf').default} title=\\"Title\\">asset</a>
|
||||
|
|
|
@ -130,7 +130,10 @@ async function processLinkNode(node: Link, context: Context) {
|
|||
return;
|
||||
}
|
||||
|
||||
const assetPath = await getAssetAbsolutePath(parsedUrl.pathname, context);
|
||||
const assetPath = await getAssetAbsolutePath(
|
||||
decodeURIComponent(parsedUrl.pathname),
|
||||
context,
|
||||
);
|
||||
if (assetPath) {
|
||||
toAssetRequireNode(node, assetPath, context.filePath);
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ import docusaurusImport from '@site/static/img/docusaurus.png';
|
|||
|
||||
export const docusaurusRequire = require('@site/static/img/docusaurus.png');
|
||||
|
||||

|
||||
|
||||
## Regular images
|
||||
|
||||
<img src={docusaurusImport} />
|
||||
|
|
BIN
website/_dogfooding/_docs tests/tests/img/oss_logo (2).png
Normal file
BIN
website/_dogfooding/_docs tests/tests/img/oss_logo (2).png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
Loading…
Add table
Reference in a new issue