import { getHighlighter, loadTheme } from "shiki";
import ws from "ws";
const websocket = new ws.Server({ port: 1234 });
let theme;
let highlighter;
const init = async () => {
highlighter = await getHighlighter({ theme: "material-darker" });
};
(async () => {
try {
await init();
} catch (e) {
}
})();
websocket.on("connection", (s) => {
s.on("message", async (msg) => {
const content = msg.toString();
const res = await shikiHighlight(content);
s.send(res);
});
});
const shikiHighlight = async (content: string): Promise<string> => {
return highlighter.codeToHtml(content, "ts");
};