Skip to content

Commit f5b5a13

Browse files
committed
params for page fragment loaders
1 parent b87e245 commit f5b5a13

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/loader.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export class LoaderResolver {
213213
const eext = fext.slice(0, -iext.length); // .zip
214214
const loader = new CommandLoader({
215215
command: command ?? commandPath,
216-
args: params ? args.concat(defineParams(params)) : args,
216+
args: withParams(args, params),
217217
path,
218218
params,
219219
root: this.root,
@@ -332,6 +332,10 @@ export class LoaderResolver {
332332
}
333333
}
334334

335+
export function withParams(args: string[], params?: Params): string[] {
336+
return params ? args.concat(defineParams(params)) : args;
337+
}
338+
335339
function defineParams(params: Params): string[] {
336340
return Object.entries(params)
337341
.filter(([name]) => /^[a-z0-9_]+$/i.test(name)) // ignore non-ASCII parameters

src/markdown.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {parseInfo} from "./info.js";
1818
import {transformJavaScriptSync} from "./javascript/module.js";
1919
import type {JavaScriptNode} from "./javascript/parse.js";
2020
import {parseJavaScript} from "./javascript/parse.js";
21+
import {withParams} from "./loader.js";
2122
import {isAssetPath, relativePath} from "./path.js";
2223
import {parsePlaceholder} from "./placeholder.js";
2324
import type {Params} from "./route.js";
@@ -282,10 +283,19 @@ export async function parseMarkdown(input: string, options: ParseOptions): Promi
282283
const root: Comment = roots.get(fragment.id);
283284
const [command, ...args] = interpreters.get(`.${fragment.tag}`)!;
284285
let target = "";
285-
const subprocess = spawn(command, args, {
286-
windowsHide: true,
287-
stdio: ["pipe", "pipe", "inherit"]
288-
});
286+
const subprocess = spawn(
287+
command,
288+
withParams(
289+
command === "sh"
290+
? args.concat("-s", "--") // TODO make this configurable
291+
: args.concat("-"), // TODO make this configurable
292+
params
293+
),
294+
{
295+
windowsHide: true,
296+
stdio: ["pipe", "pipe", "inherit"]
297+
}
298+
);
289299
subprocess.stdin.write(fragment.source);
290300
subprocess.stdin.end();
291301
subprocess.stdout.on("data", (data) => {

0 commit comments

Comments
 (0)