Files
plainleaf/client/plugos/syscalls/language.ts
T
Zef Hemel 431bf787ac Optimization: chunk up all coding languages
Even though the service worker will proactively cache them in the
browser, the browser will not have to load them, parse them, interpret
them unless these languages are actually used. Less JS to load, less
waiting.
2026-03-28 16:49:24 +01:00

28 lines
760 B
TypeScript

import type { SysCallMapping } from "../system.ts";
import { parse } from "../../markdown_parser/parse_tree.ts";
import type { ParseTree } from "@silverbulletmd/silverbullet/lib/tree";
import {
allLanguageNames,
languageFor,
loadLanguageFor,
} from "../../languages.ts";
export function languageSyscalls(): SysCallMapping {
return {
"language.parseLanguage": async (
_ctx,
language: string,
code: string,
): Promise<ParseTree> => {
const lang = languageFor(language) ?? await loadLanguageFor(language);
if (!lang) {
throw new Error(`Unknown language ${language}`);
}
return parse(lang, code);
},
"language.listLanguages": (): string[] => {
return allLanguageNames;
},
};
}