Skip to content

Commit 886364e

Browse files
authored
Double-escape back-slashes (#11)
* keep require.resolve for runtime.js * use path.resolve * replace backslash with double backslash
1 parent 4641d7f commit 886364e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/loader.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const Markdoc = require('@markdoc/markdoc');
44

55
const DEFAULT_SCHEMA_PATH = './markdoc';
66

7+
function normalize(s) {
8+
return s.replace(/\\/g, '\\\\');
9+
}
10+
711
async function gatherPartials(ast, schemaDir) {
812
let partials = {};
913

@@ -128,7 +132,7 @@ async function load(source) {
128132
async function readDir(variable) {
129133
try {
130134
const module = await resolve(schemaDir, variable);
131-
return `import * as ${variable} from '${module}'`;
135+
return `import * as ${variable} from '${normalize(module)}'`;
132136
} catch (error) {
133137
return `const ${variable} = {};`;
134138
}
@@ -162,7 +166,7 @@ import yaml from 'js-yaml';
162166
// renderers is imported separately so Markdoc isn't sent to the client
163167
import Markdoc, {renderers} from '@markdoc/markdoc'
164168
165-
import {getSchema} from '${await resolve(__dirname, './runtime')}';
169+
import {getSchema} from '${normalize(await resolve(__dirname, './runtime'))}';
166170
/**
167171
* Schema is imported like this so end-user's code is compiled using build-in babel/webpack configs.
168172
* This enables typescript/ESnext support

0 commit comments

Comments
 (0)