Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions client/components/OCodeBlock.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<script setup lang="ts">
import type { BundledLanguage } from 'shiki'
import { computed } from 'vue'
import { renderCodeHighlight } from '../composables/shiki'

const props = withDefaults(
defineProps<{
code: string
lang?: BundledLanguage
lang: 'javascript'
lines?: boolean
transformRendered?: (code: string) => string
}>(),
Expand Down
36 changes: 15 additions & 21 deletions client/composables/shiki.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
import type { Highlighter, BundledLanguage } from 'shiki'
import { createHighlighter } from 'shiki'
import { computed, ref, toValue } from 'vue'
import type { MaybeRef } from '@vueuse/core'
import type { HighlighterCore } from 'shiki'
import { createHighlighterCore } from 'shiki/core'
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript'
import { computed, ref, toValue } from 'vue'
import { devtools } from './rpc'

export const shiki = ref<Highlighter>()
export const shiki = ref<HighlighterCore>()

export function loadShiki() {
// Only loading when needed
return createHighlighter({
export async function loadShiki() {
shiki.value = await createHighlighterCore({
themes: [
'vitesse-dark',
'vitesse-light',
import('@shikijs/themes/vitesse-light'),
import('@shikijs/themes/vitesse-dark'),
],
langs: [
'css',
'javascript',
'typescript',
'html',
'vue',
'vue-html',
'bash',
'diff',
import('@shikijs/langs/javascript'),
],
}).then((i) => {
shiki.value = i
engine: createJavaScriptRegexEngine(),
})

return shiki.value
}

export function renderCodeHighlight(code: MaybeRef<string>, lang: BundledLanguage) {
export function renderCodeHighlight(code: MaybeRef<string>, lang: 'javascript') {
return computed(() => {
const colorMode = devtools.value?.colorMode || 'light'
return shiki.value!.codeToHtml(toValue(code), {
return shiki.value!.codeToHtml(toValue(code) || '', {
lang,
theme: colorMode === 'dark' ? 'vitesse-dark' : 'vitesse-light',
}) || ''
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@nuxt/scripts",
"type": "module",
"version": "0.10.3",
"packageManager": "pnpm@10.4.0",
"packageManager": "pnpm@10.4.1",
"description": "Load third-party scripts with better performance, privacy and DX in Nuxt Apps.",
"author": {
"website": "https://harlanzw.com",
Expand Down