mirror of
https://github.com/one-among-us/data.git
synced 2024-12-29 13:12:40 +08:00
29 lines
727 B
TypeScript
29 lines
727 B
TypeScript
import * as mdx from "@mdx-js/mdx";
|
|
import * as swc from "@swc/core";
|
|
import remarkMath from 'remark-math';
|
|
import rehypeKatex from 'rehype-katex';
|
|
|
|
export function renderMdx(markdown: string): string {
|
|
const esmCode = mdx.compileSync(markdown, {
|
|
jsxRuntime: "classic",
|
|
pragma: "Vue.h",
|
|
pragmaFrag: "Vue.Fragment",
|
|
pragmaImportSource: "vue",
|
|
remarkPlugins: [remarkMath],
|
|
rehypePlugins: [rehypeKatex]
|
|
}).value.toString("utf-8");
|
|
|
|
const codeRemovedImport = esmCode.replace(/^import .*$/m, "");
|
|
|
|
return swc.transformSync(codeRemovedImport, {
|
|
jsc: {
|
|
parser: {
|
|
syntax: "ecmascript"
|
|
},
|
|
loose: true,
|
|
},
|
|
minify: true,
|
|
module: { type: "commonjs" },
|
|
}).code;
|
|
}
|