From: Mark Otto Date: Mon, 20 Oct 2025 18:07:54 +0000 (-0700) Subject: Migrate from Prism to Shiki X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=refs%2Fheads%2Fv6-shiki;p=thirdparty%2Fbootstrap.git Migrate from Prism to Shiki --- 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 ---