mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 23:57:22 +02:00
fix(v2): fix encoding of markdown image/file inline file-loaders (#4736)
* try to reproduce windows edge case due to file encoding * mdx loader => required file paths should be escaped * revert bad change * try to fix posix path issues * try to fix posix path issues * attempt to fix the file-loader edge cases with non-ascii chars * Add more example image edge-cases
This commit is contained in:
parent
39105f03d4
commit
a79c70c954
12 changed files with 148 additions and 40 deletions
|
@ -11,7 +11,11 @@ const url = require('url');
|
|||
const fs = require('fs-extra');
|
||||
const escapeHtml = require('escape-html');
|
||||
const {getFileLoaderUtils} = require('@docusaurus/core/lib/webpack/utils');
|
||||
const {posixPath, toMessageRelativeFilePath} = require('@docusaurus/utils');
|
||||
const {
|
||||
posixPath,
|
||||
escapePath,
|
||||
toMessageRelativeFilePath,
|
||||
} = require('@docusaurus/utils');
|
||||
|
||||
const {
|
||||
loaders: {inlineMarkdownImageFileLoader},
|
||||
|
@ -22,7 +26,9 @@ const createJSX = (node, pathUrl) => {
|
|||
jsxNode.type = 'jsx';
|
||||
jsxNode.value = `<img ${node.alt ? `alt={"${escapeHtml(node.alt)}"} ` : ''}${
|
||||
node.url
|
||||
? `src={require("${inlineMarkdownImageFileLoader}${pathUrl}").default}`
|
||||
? `src={require("${inlineMarkdownImageFileLoader}${escapePath(
|
||||
pathUrl,
|
||||
)}").default}`
|
||||
: ''
|
||||
}${node.title ? ` title="${escapeHtml(node.title)}"` : ''} />`;
|
||||
|
||||
|
|
|
@ -5,7 +5,11 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
const {toMessageRelativeFilePath, posixPath} = require('@docusaurus/utils');
|
||||
const {
|
||||
toMessageRelativeFilePath,
|
||||
posixPath,
|
||||
escapePath,
|
||||
} = require('@docusaurus/utils');
|
||||
|
||||
const visit = require('unist-util-visit');
|
||||
const path = require('path');
|
||||
|
@ -43,7 +47,9 @@ function toAssetRequireNode({node, filePath, requireAssetPath}) {
|
|||
? relativeRequireAssetPath
|
||||
: `./${relativeRequireAssetPath}`;
|
||||
|
||||
const href = `require('${inlineMarkdownLinkFileLoader}${relativeRequireAssetPath}').default`;
|
||||
const href = `require('${inlineMarkdownLinkFileLoader}${escapePath(
|
||||
relativeRequireAssetPath,
|
||||
)}').default`;
|
||||
const children = (node.children || []).map((n) => toValue(n)).join('');
|
||||
const title = node.title ? `title="${escapeHtml(node.title)}"` : '';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue