1
0
silverbullet/web/syscalls/code_widget.ts

25 lines
649 B
TypeScript
Raw Normal View History

2023-10-29 09:02:50 +00:00
import { CodeWidgetContent } from "$sb/types.ts";
import { SysCallMapping } from "../../plugos/system.ts";
2023-10-31 09:33:38 +00:00
import { CodeWidgetHook } from "../hooks/code_widget.ts";
2023-10-31 09:33:38 +00:00
export function codeWidgetSyscalls(
codeWidgetHook: CodeWidgetHook,
): SysCallMapping {
return {
2023-10-31 09:33:38 +00:00
"codeWidget.render": (
_ctx,
lang: string,
body: string,
2023-10-31 09:33:38 +00:00
pageName: string,
2023-10-29 09:02:50 +00:00
): Promise<CodeWidgetContent> => {
2023-10-31 09:33:38 +00:00
const langCallback = codeWidgetHook.codeWidgetCallbacks.get(
lang,
);
if (!langCallback) {
throw new Error(`Code widget ${lang} not found`);
}
2023-10-31 09:33:38 +00:00
return langCallback(body, pageName);
},
};
}