From e979822f7c40a1e545ddae1e6139980809799305 Mon Sep 17 00:00:00 2001 From: uiolee <22849383+uiolee@users.noreply.github.com> Date: Tue, 12 Sep 2023 21:18:54 +0800 Subject: [PATCH] fix: windos escapeBackslash --- lib/plugins/tag/include_code.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/plugins/tag/include_code.ts b/lib/plugins/tag/include_code.ts index 2acd3d2546..b2f09e972b 100644 --- a/lib/plugins/tag/include_code.ts +++ b/lib/plugins/tag/include_code.ts @@ -13,6 +13,11 @@ const rTo = /\s*to:(\d+)/i; * {% include_code [title] [lang:language] path/to/file %} */ +const escapeBackslash = path => { + // Replace backslashes on Windows + return path.replace(/\\/g, '/'); +}; + export = (ctx: Hexo) => function includeCodeTag(args: string[]) { let codeDir = ctx.config.code_dir; let arg = args.join(' '); @@ -46,7 +51,7 @@ export = (ctx: Hexo) => function includeCodeTag(args: string[]) { // If the language is not defined, use file extension instead lang = lang || extname(path).substring(1); - const src = join(codeDir, path); + const src = escapeBackslash(join(codeDir, path)); // If the title is not defined, use file name instead const title = match[1] || basename(path); @@ -72,6 +77,5 @@ export = (ctx: Hexo) => function includeCodeTag(args: string[]) { args: [code, options] }); } - return `
${code}
`;
};