silverbullet/web/syscalls/code_widget.ts

25 lines
686 B
TypeScript
Raw Normal View History

2024-07-30 23:33:33 +08:00
import type { CodeWidgetContent } from "../../plug-api/types.ts";
import type { SysCallMapping } from "../../lib/plugos/system.ts";
import type { CodeWidgetHook } from "../hooks/code_widget.ts";
2023-10-31 17:33:38 +08:00
export function codeWidgetSyscalls(
codeWidgetHook: CodeWidgetHook,
): SysCallMapping {
return {
2023-10-31 17:33:38 +08:00
"codeWidget.render": (
_ctx,
lang: string,
body: string,
2023-10-31 17:33:38 +08:00
pageName: string,
): Promise<CodeWidgetContent | null> => {
2023-10-31 17:33:38 +08:00
const langCallback = codeWidgetHook.codeWidgetCallbacks.get(
lang,
);
if (!langCallback) {
throw new Error(`Code widget ${lang} not found`);
}
2023-10-31 17:33:38 +08:00
return langCallback(body, pageName);
},
};
}