From 92ad858ee5bf810141d7e58004e3be47ec95da38 Mon Sep 17 00:00:00 2001 From: Ben Holmes Date: Thu, 24 Mar 2022 17:48:07 -0400 Subject: [PATCH] Refactor: move prism to `@astrojs/prism/components` (#2878) * feat: add `` to @astrojs/prism/components * feat: remove `` from astro/components * refactor: point to index.mjs in import * refactor: change exp to @astrojs/prism/component * refactor: remove unecessary index.js * chore: changeset --- components/Prism.astro | 49 ------------------------------------------ components/index.js | 1 - 2 files changed, 50 deletions(-) delete mode 100644 components/Prism.astro diff --git a/components/Prism.astro b/components/Prism.astro deleted file mode 100644 index 5f92b1f667e4..000000000000 --- a/components/Prism.astro +++ /dev/null @@ -1,49 +0,0 @@ ---- -import Prism from 'prismjs'; -import { addAstro } from '@astrojs/prism'; -import loadLanguages from 'prismjs/components/index.js'; - -export interface Props { - class?: string; - lang?: string; - code: string; -} - -const { class: className, lang, code } = Astro.props as Props; - -let classLanguage = `language-${lang}`; - -const languageMap = new Map([['ts', 'typescript']]); - -if (lang == null) { - console.warn('Prism.astro: No language provided.'); -} - -const ensureLoaded = (lang) => { - if (lang && !Prism.languages[lang]) { - loadLanguages([lang]); - } -}; - -if (languageMap.has(lang)) { - ensureLoaded(languageMap.get(lang)); -} else if (lang === 'astro') { - ensureLoaded('typescript'); - addAstro(Prism); -} else { - ensureLoaded('markup-templating'); // Prism expects this to exist for a number of other langs - ensureLoaded(lang); -} - -if (lang && !Prism.languages[lang]) { - console.warn(`Unable to load the language: ${lang}`); -} - -const grammar = Prism.languages[lang]; -let html = code; -if (grammar) { - html = Prism.highlight(code, grammar, lang); -} ---- - -
diff --git a/components/index.js b/components/index.js index 8b19c7d1f2c3..b16d8983ac48 100644 --- a/components/index.js +++ b/components/index.js @@ -1,4 +1,3 @@ export { default as Code } from './Code.astro'; export { default as Debug } from './Debug.astro'; export { default as Markdown } from './Markdown.astro'; -export { default as Prism } from './Prism.astro';