//@ts-ignore
import { compile, escapeSvelte } from "mdsvex";
import { createHighlighter } from "shiki";
import { kanagawa_dark as theme } from "$lib/kanagawa"


const highlighter = await createHighlighter({
  themes: [theme],
  langs: ["javascript", "typescript", "shell"],
});

export default async function compileArticle(code: string) {
  return compile(code, {
    highlight: {
      highlighter: async (code: string, lang = "text") => {
        const html = escapeSvelte(
          highlighter.codeToHtml(code, { lang, theme }),
        );
        return html;
      },
    },
  });
}