From 75a7c38b9954a1e14c4ddec5b86696bfc9a73e7e Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Mon, 20 Oct 2025 11:07:54 -0700 Subject: [PATCH] Migrate from Prism to Shiki --- site/astro.config.ts | 8 +- site/src/components/shortcodes/Code.astro | 40 ++++- site/src/content/docs/utilities/display.mdx | 4 +- site/src/libs/astro.ts | 4 +- site/src/scss/_syntax.scss | 159 +++----------------- 5 files changed, 69 insertions(+), 146 deletions(-) diff --git a/site/astro.config.ts b/site/astro.config.ts index 400330f4a4..de9a1433bb 100644 --- a/site/astro.config.ts +++ b/site/astro.config.ts @@ -24,7 +24,13 @@ export default defineConfig({ integrations: [bootstrap()], markdown: { smartypants: false, - syntaxHighlight: 'prism' + syntaxHighlight: 'shiki', + shikiConfig: { + themes: { + light: 'github-light', + dark: 'github-dark' + } + } }, site, vite: { diff --git a/site/src/components/shortcodes/Code.astro b/site/src/components/shortcodes/Code.astro index ba2c61165f..6377aaeaeb 100644 --- a/site/src/components/shortcodes/Code.astro +++ b/site/src/components/shortcodes/Code.astro @@ -1,7 +1,7 @@ --- import fs from 'node:fs' import path from 'node:path' -import { Prism } from '@astrojs/prism' +import { codeToHtml } from 'shiki' interface Props { /** @@ -57,6 +57,40 @@ if (filePath && fileMatch && codeToDisplay) { codeToDisplay = match[0] } + +// Add line wrapper for shell languages to support shell prompts +const shouldWrapLines = lang && ['bash', 'sh', 'powershell'].includes(lang) + +const highlightedCode = codeToDisplay && lang + ? await codeToHtml(codeToDisplay, { + lang, + themes: { + light: 'github-light', + dark: 'github-dark' + }, + transformers: shouldWrapLines ? [ + { + name: 'line-wrapper', + line(node) { + // Wrap non-comment lines in a span with .line class for shell prompt styling + const hasOnlyComments = node.children.every(child => + child.type === 'element' && + child.properties?.class && + Array.isArray(child.properties.class) && + child.properties.class.some((cls) => typeof cls === 'string' && cls.includes('comment')) + ) + + if (!hasOnlyComments) { + node.properties = node.properties || {} + node.properties.class = node.properties.class + ? `${node.properties.class} line` + : 'line' + } + } + } + ] : [] + }) + : null ---