Skip to content

Commit

Permalink
params for page fragment loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Nov 10, 2024
1 parent b87e245 commit f5b5a13
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
18 changes: 14 additions & 4 deletions src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit f5b5a13

Please sign in to comment.