mirror of
https://github.com/one-among-us/data.git
synced 2024-11-23 03:27:38 +08:00
25 lines
574 B
TypeScript
25 lines
574 B
TypeScript
|
import * as mdx from "xdm";
|
||
|
import * as swc from "@swc/core";
|
||
|
|
||
|
export function renderMdx(markdown: string): string {
|
||
|
const esmCode = mdx.compileSync(markdown, {
|
||
|
jsxRuntime: "classic",
|
||
|
pragma: "Vue.h",
|
||
|
pragmaFrag: "Vue.Fragment",
|
||
|
pragmaImportSource: "vue"
|
||
|
}).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;
|
||
|
}
|