Skip to content

Commit

Permalink
fix: use js engine of shiki to avoid wasm error
Browse files Browse the repository at this point in the history
  • Loading branch information
elevatebart committed Jan 25, 2025
1 parent dd8cc9c commit 4802dc1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/composables/getMDCParser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {MDParser} from "./useMarkdownParser"
import {loadWasm} from "shiki/engine/oniguruma"


let parser:MDParser

Expand All @@ -12,8 +12,6 @@ export default async function getMDCParser() {

const useMarkdownParser = mdParserExport.default ?? mdParserExport

// import wasm as assets
await loadWasm(import("shiki/wasm"))
parser = await useMarkdownParser();
return parser
}
5 changes: 4 additions & 1 deletion src/composables/useMarkdownParser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {createMarkdownParser, createShikiHighlighter, rehypeHighlight} from "@nuxtjs/mdc/runtime";
import {createJavaScriptRegexEngine} from "shiki/engine/javascript"
import type {MDCParserResult} from "@nuxtjs/mdc";
import GithubLight from "shiki/themes/github-light.mjs";
import GithubDark from "shiki/themes/github-dark.mjs";
Expand Down Expand Up @@ -65,11 +66,12 @@ const langsMap: Record<string, any> = {

export type MDParser = (md: string) => Promise<MDCParserResult>

export default function useMarkdownParser() {
export default async function useMarkdownParser() {
let parser: MDParser;

return async (markdown:string) => {
if (!parser) {

const {bundledLanguagesInfo} = await import("shiki/langs");


Expand Down Expand Up @@ -97,6 +99,7 @@ export default function useMarkdownParser() {
highlighter: createShikiHighlighter({
// Configure the bundled languages
bundledLangs: langsMap,
engine: createJavaScriptRegexEngine() as any
}),
},
}
Expand Down

1 comment on commit 4802dc1

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.