Skip to content

Commit

Permalink
fix: windos escapeBackslash
Browse files Browse the repository at this point in the history
  • Loading branch information
uiolee authored and stevenjoezhang committed Apr 6, 2024
1 parent 6a7a31b commit e979822
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/plugins/tag/include_code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ');
Expand Down Expand Up @@ -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);
Expand All @@ -72,6 +77,5 @@ export = (ctx: Hexo) => function includeCodeTag(args: string[]) {
args: [code, options]
});
}

return `<pre><code>${code}</code></pre>`;
};

0 comments on commit e979822

Please sign in to comment.