Skip to content

Commit 6b2f81a

Browse files
committed
fix: use shiki/core + javascript engine
1 parent e2a35ad commit 6b2f81a

3 files changed

Lines changed: 36 additions & 24 deletions

File tree

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
"@nuxt/fonts": "^0.12.1",
3030
"@nuxt/scripts": "^0.13.2",
3131
"@nuxtjs/html-validator": "^2.1.0",
32+
"@shikijs/langs": "^3.21.0",
33+
"@shikijs/themes": "^3.21.0",
3234
"nuxt": "https://pkg.pr.new/nuxt@8d4f9ba",
3335
"nuxt-og-image": "^5.1.13",
3436
"perfect-debounce": "^2.1.0",

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/utils/readme.ts

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { marked, type Tokens } from 'marked'
22
import sanitizeHtml from 'sanitize-html'
3-
import { createHighlighter, type Highlighter } from 'shiki'
3+
import { createHighlighterCore, type HighlighterCore } from 'shiki/core'
4+
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript'
45
import { hasProtocol } from 'ufo'
56

67
// only allow h3-h6 since we shift README headings down by 2 levels
@@ -40,33 +41,36 @@ const ALLOWED_ATTR: Record<string, string[]> = {
4041
// GitHub-style callout types
4142
// Format: > [!NOTE], > [!TIP], > [!IMPORTANT], > [!WARNING], > [!CAUTION]
4243

43-
// Singleton highlighter instance
44-
let highlighter: Highlighter | null = null
44+
// Singleton highlighter instance using JavaScript engine (no WASM needed)
45+
let highlighter: HighlighterCore | null = null
4546

46-
async function getHighlighter(): Promise<Highlighter> {
47+
async function getHighlighter(): Promise<HighlighterCore> {
4748
if (!highlighter) {
48-
highlighter = await createHighlighter({
49-
themes: ['github-dark'],
49+
highlighter = await createHighlighterCore({
50+
themes: [
51+
import('@shikijs/themes/github-dark'),
52+
],
5053
langs: [
51-
'javascript',
52-
'typescript',
53-
'json',
54-
'html',
55-
'css',
56-
'bash',
57-
'shell',
58-
'markdown',
59-
'yaml',
60-
'vue',
61-
'jsx',
62-
'tsx',
63-
'diff',
64-
'sql',
65-
'graphql',
66-
'python',
67-
'rust',
68-
'go',
54+
import('@shikijs/langs/javascript'),
55+
import('@shikijs/langs/typescript'),
56+
import('@shikijs/langs/json'),
57+
import('@shikijs/langs/html'),
58+
import('@shikijs/langs/css'),
59+
import('@shikijs/langs/bash'),
60+
import('@shikijs/langs/shell'),
61+
import('@shikijs/langs/markdown'),
62+
import('@shikijs/langs/yaml'),
63+
import('@shikijs/langs/vue'),
64+
import('@shikijs/langs/jsx'),
65+
import('@shikijs/langs/tsx'),
66+
import('@shikijs/langs/diff'),
67+
import('@shikijs/langs/sql'),
68+
import('@shikijs/langs/graphql'),
69+
import('@shikijs/langs/python'),
70+
import('@shikijs/langs/rust'),
71+
import('@shikijs/langs/go'),
6972
],
73+
engine: createJavaScriptRegexEngine(),
7074
})
7175
}
7276
return highlighter

0 commit comments

Comments
 (0)