mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-07 21:32:38 +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
|
@ -21,9 +21,14 @@ import {
|
|||
// @ts-expect-error: no typedefs :s
|
||||
import resolvePathnameUnsafe from 'resolve-pathname';
|
||||
|
||||
import {posixPath as posixPathImport} from './posixPath';
|
||||
|
||||
export const posixPath = posixPathImport;
|
||||
|
||||
export * from './codeTranslationsUtils';
|
||||
export * from './markdownParser';
|
||||
export * from './markdownLinks';
|
||||
export * from './escapePath';
|
||||
|
||||
const fileHash = new Map();
|
||||
export async function generate(
|
||||
|
@ -129,20 +134,6 @@ export function genComponentName(pagePath: string): string {
|
|||
return upperFirst(camelCase(pageHash));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert Windows backslash paths to posix style paths.
|
||||
* E.g: endi\\lie -> endi/lie
|
||||
*/
|
||||
export function posixPath(str: string): string {
|
||||
const isExtendedLengthPath = /^\\\\\?\\/.test(str);
|
||||
const hasNonAscii = /[^\u0000-\u0080]+/.test(str); // eslint-disable-line
|
||||
|
||||
if (isExtendedLengthPath || hasNonAscii) {
|
||||
return str;
|
||||
}
|
||||
return str.replace(/\\/g, '/');
|
||||
}
|
||||
|
||||
// When you want to display a path in a message/warning/error,
|
||||
// it's more convenient to:
|
||||
// - make it relative to cwd()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue