diff --git a/src/loader.ts b/src/loader.ts index e351e2220..1d5740b7a 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -213,7 +213,7 @@ export class LoaderResolver { const eext = fext.slice(0, -iext.length); // .zip const loader = new CommandLoader({ command: command ?? commandPath, - args: params ? args.concat(defineParams(params)) : args, + args: withParams(args, params), path, params, root: this.root, @@ -332,6 +332,10 @@ export class LoaderResolver { } } +export function withParams(args: string[], params?: Params): string[] { + return params ? args.concat(defineParams(params)) : args; +} + function defineParams(params: Params): string[] { return Object.entries(params) .filter(([name]) => /^[a-z0-9_]+$/i.test(name)) // ignore non-ASCII parameters diff --git a/src/markdown.ts b/src/markdown.ts index a9d2e6d6e..52834aa1a 100644 --- a/src/markdown.ts +++ b/src/markdown.ts @@ -18,6 +18,7 @@ import {parseInfo} from "./info.js"; import {transformJavaScriptSync} from "./javascript/module.js"; import type {JavaScriptNode} from "./javascript/parse.js"; import {parseJavaScript} from "./javascript/parse.js"; +import {withParams} from "./loader.js"; import {isAssetPath, relativePath} from "./path.js"; import {parsePlaceholder} from "./placeholder.js"; import type {Params} from "./route.js"; @@ -282,10 +283,19 @@ export async function parseMarkdown(input: string, options: ParseOptions): Promi const root: Comment = roots.get(fragment.id); const [command, ...args] = interpreters.get(`.${fragment.tag}`)!; let target = ""; - const subprocess = spawn(command, args, { - windowsHide: true, - stdio: ["pipe", "pipe", "inherit"] - }); + const subprocess = spawn( + command, + withParams( + command === "sh" + ? args.concat("-s", "--") // TODO make this configurable + : args.concat("-"), // TODO make this configurable + params + ), + { + windowsHide: true, + stdio: ["pipe", "pipe", "inherit"] + } + ); subprocess.stdin.write(fragment.source); subprocess.stdin.end(); subprocess.stdout.on("data", (data) => {