From: Julien Déramond Date: Tue, 17 Mar 2026 18:27:37 +0000 (+0100) Subject: Remove `src/libs/prism.ts` and clean up Prism old code (#42182) X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9c9d2d7d93af2558b18751f07ef68ed50a4e2b0b;p=thirdparty%2Fbootstrap.git Remove `src/libs/prism.ts` and clean up Prism old code (#42182) --- diff --git a/package-lock.json b/package-lock.json index b288c43451..635bed3537 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,7 +36,6 @@ "@stackblitz/sdk": "^1.11.0", "@types/js-yaml": "^4.0.9", "@types/mime": "^4.0.0", - "@types/prismjs": "^1.26.5", "astro": "^5.16.6", "astro-auto-import": "^0.4.5", "astro-broken-links-checker": "^1.0.7", @@ -5032,13 +5031,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/prismjs": { - "version": "1.26.5", - "resolved": "https://registry.npmjs.org/@types/prismjs/-/prismjs-1.26.5.tgz", - "integrity": "sha512-AUZTa7hQ2KY5L7AmtSiqxlhWxb4ina0yd8hNbl4TWuqnv/pFP0nDMb3YrfSBf4hJVGLh2YEIBfKaBW/9UEl6IQ==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/resolve": { "version": "1.20.2", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", diff --git a/package.json b/package.json index a078f1c6a3..adbd6fb620 100644 --- a/package.json +++ b/package.json @@ -136,7 +136,6 @@ "@stackblitz/sdk": "^1.11.0", "@types/js-yaml": "^4.0.9", "@types/mime": "^4.0.0", - "@types/prismjs": "^1.26.5", "astro": "^5.16.6", "astro-auto-import": "^0.4.5", "astro-broken-links-checker": "^1.0.7", diff --git a/site/src/components/shortcodes/Code.astro b/site/src/components/shortcodes/Code.astro index 03c81e3fa1..292877ee03 100644 --- a/site/src/components/shortcodes/Code.astro +++ b/site/src/components/shortcodes/Code.astro @@ -38,7 +38,7 @@ interface Props { 'data-language'?: string /** * The language to use for highlighting. - * @see https://prismjs.com/#supported-languages + * @see https://shiki.style/languages */ lang?: string /** diff --git a/site/src/libs/astro.ts b/site/src/libs/astro.ts index b282fc6b22..71c60a5c37 100644 --- a/site/src/libs/astro.ts +++ b/site/src/libs/astro.ts @@ -10,7 +10,6 @@ import rehypeAutolinkHeadings from 'rehype-autolink-headings' import { getConfig } from './config' import { rehypeBsTable } from './rehype' import { remarkBsConfig, remarkBsDocsref } from './remark' -// import { configurePrism } from './prism' import { docsDirectory, getDocsFsPath, @@ -38,8 +37,6 @@ const headingsRangeRegex = new RegExp(`^h[${getConfig().anchors.min}-${getConfig export function bootstrap(): AstroIntegration[] { const sitemapExcludedUrls = sitemapExcludes.map((url) => `${getConfig().baseURL}${url}/`) - // configurePrism() - return [ bootstrap_auto_import(), { diff --git a/site/src/libs/prism.ts b/site/src/libs/prism.ts deleted file mode 100644 index 3b9ef8c9da..0000000000 --- a/site/src/libs/prism.ts +++ /dev/null @@ -1,93 +0,0 @@ -import Prism, { type hooks } from 'prismjs' -const { Token } = Prism - -let isPrismConfigured = false - -export function configurePrism() { - if (isPrismConfigured) { - return - } - - isPrismConfigured = true - - Prism.hooks.add('after-tokenize', lineWrapPlugin) -} - -// A plugin to wrap each line in a .line span, except for comments and empty lines -function lineWrapPlugin(env: hooks.HookEnvironmentMap['after-tokenize']) { - // Skip processing if the language isn't one we want to modify - if (env.language !== 'bash' && env.language !== 'sh' && env.language !== 'powershell') { - return - } - - // First, split tokens into lines - const lines: (string | Prism.Token)[][] = [[]] - - for (let i = 0; i < env.tokens.length; i++) { - const token = env.tokens[i] - - if (typeof token === 'string') { - // Split string tokens by newlines - const parts = token.split('\n') - - for (let j = 0; j < parts.length; j++) { - if (j > 0) { - // Start a new line after each newline - lines.push([]) - } - - if (parts[j]) { - lines[lines.length - 1].push(parts[j]) - } - } - } else { - lines[lines.length - 1].push(token) - } - } - - // Now rebuild tokens with the line structure - env.tokens = [] - - for (let i = 0; i < lines.length; i++) { - const line = lines[i] - - // Check if this is an empty line - const isEmptyLine = line.length === 0 || (line.length === 1 && typeof line[0] === 'string' && line[0].trim() === '') - - // Check if this is a comment-only line - const isCommentLine = line.every((token) => { - if (typeof token === 'string') { - return token.trim() === '' - } - return token.type === 'comment' - }) - - if (isEmptyLine || isCommentLine) { - // For comment or empty lines, just add the tokens without a wrapper - env.tokens.push(...line) - - // Add a newline after each line (except the last) - if (i < lines.length - 1) { - env.tokens.push('\n') - } - } else { - // For normal lines, wrap with .line class - const lineToken = new Token('span', '', ['line']) - const lineChildren: (string | Prism.Token)[] = [] - - // Add the line content - lineChildren.push(...line) - - // For the last token in the line, append a newline - if (i < lines.length - 1) { - lineChildren.push('\n') - } - - // Set line content - lineToken.content = lineChildren - - // Add the entire structure to tokens - env.tokens.push(lineToken) - } - } -}