Skip to content

Commit

Permalink
Remove pre-shiki v0.14 theme names (#8169)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Aug 21, 2023
1 parent 15471e6 commit e79e377
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 80 deletions.
14 changes: 14 additions & 0 deletions .changeset/spicy-icons-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'@astrojs/markdoc': minor
'@astrojs/mdx': minor
'@astrojs/markdown-remark': major
'astro': major
---

Remove pre-shiki v0.14 theme names for compatibility. Please rename to the new theme names to migrate:

- `material-darker` -> `material-theme-darker`
- `material-default` -> `material-theme`
- `material-lighter` -> `material-theme-lighter`
- `material-ocean` -> `material-theme-ocean`
- `material-palenight` -> `material-theme-palenight`
6 changes: 0 additions & 6 deletions packages/astro/components/shiki-themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,4 @@ export const themes = {
'solarized-light': () => import('shiki/themes/solarized-light.json').then(mod => mod.default),
'vitesse-dark': () => import('shiki/themes/vitesse-dark.json').then(mod => mod.default),
'vitesse-light': () => import('shiki/themes/vitesse-light.json').then(mod => mod.default),
// old theme names for compat
'material-darker': () => import('shiki/themes/material-theme-darker').then(mod => mod.default),
'material-default': () => import('shiki/themes/material-theme').then(mod => mod.default),
'material-lighter': () => import('shiki/themes/material-theme-lighter').then(mod => mod.default),
'material-ocean': () => import('shiki/themes/material-theme-ocean').then(mod => mod.default),
'material-palenight': () => import('shiki/themes/material-theme-palenight').then(mod => mod.default),
};
13 changes: 0 additions & 13 deletions packages/astro/scripts/shiki-gen-themes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,6 @@ const themeImports = dir.map((f) => {
return [f.slice(0, f.indexOf('.json')), toThemeImport(f)];
});

// Map of old theme names to new names to preserve compatibility when we upgrade shiki
const compatThemes = {
'material-darker': 'material-theme-darker',
'material-default': 'material-theme',
'material-lighter': 'material-theme-lighter',
'material-ocean': 'material-theme-ocean',
'material-palenight': 'material-theme-palenight',
};

let code = `\
/**
* This file is prebuilt from packages/astro/scripts/shiki-gen-themes.mjs
Expand All @@ -29,10 +20,6 @@ export const themes = {`;
for (const [key, imp] of themeImports) {
code += `\n\t'${key}': () => ${imp},`;
}
code += `\n\t// old theme names for compat`;
for (const oldName in compatThemes) {
code += `\n\t'${oldName}': () => ${toThemeImport(compatThemes[oldName])},`;
}
code += '\n};';

// eslint-disable-next-line no-console
Expand Down
21 changes: 0 additions & 21 deletions packages/integrations/markdoc/src/extensions/shiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,6 @@ import type * as shikiTypes from 'shiki';
import { getHighlighter } from 'shiki';
import type { AstroMarkdocConfig } from '../config.js';

// Map of old theme names to new names to preserve compatibility when we upgrade shiki
const compatThemes: Record<string, string> = {
'material-darker': 'material-theme-darker',
'material-default': 'material-theme',
'material-lighter': 'material-theme-lighter',
'material-ocean': 'material-theme-ocean',
'material-palenight': 'material-theme-palenight',
};

const normalizeTheme = (theme: string | shikiTypes.IShikiTheme) => {
if (typeof theme === 'string') {
return compatThemes[theme] || theme;
} else if (compatThemes[theme.name]) {
return { ...theme, name: compatThemes[theme.name] };
} else {
return theme;
}
};

const ASTRO_COLOR_REPLACEMENTS = {
'#000001': 'var(--astro-code-color-text)',
'#000002': 'var(--astro-code-color-background)',
Expand Down Expand Up @@ -53,8 +34,6 @@ export default async function shiki({
theme = 'github-dark',
wrap = false,
}: ShikiConfig = {}): Promise<AstroMarkdocConfig> {
theme = normalizeTheme(theme);

const cacheID: string = typeof theme === 'string' ? theme : theme.name;
if (!highlighterCache.has(cacheID)) {
highlighterCache.set(
Expand Down
20 changes: 0 additions & 20 deletions packages/integrations/mdx/src/remark-shiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,7 @@ import { visit } from 'unist-util-visit';
*/
const highlighterCacheAsync = new Map<string, Promise<shiki.Highlighter>>();

// Map of old theme names to new names to preserve compatibility when we upgrade shiki
const compatThemes: Record<string, string> = {
'material-darker': 'material-theme-darker',
'material-default': 'material-theme',
'material-lighter': 'material-theme-lighter',
'material-ocean': 'material-theme-ocean',
'material-palenight': 'material-theme-palenight',
};

const normalizeTheme = (theme: string | shiki.IShikiTheme) => {
if (typeof theme === 'string') {
return compatThemes[theme] || theme;
} else if (compatThemes[theme.name]) {
return { ...theme, name: compatThemes[theme.name] };
} else {
return theme;
}
};

const remarkShiki = async ({ langs = [], theme = 'github-dark', wrap = false }: ShikiConfig) => {
theme = normalizeTheme(theme);
const cacheID: string = typeof theme === 'string' ? theme : theme.name;
let highlighterAsync = highlighterCacheAsync.get(cacheID);
if (!highlighterAsync) {
Expand Down
20 changes: 0 additions & 20 deletions packages/markdown/remark/src/remark-shiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,10 @@ import type { ShikiConfig } from './types.js';
*/
const highlighterCacheAsync = new Map<string, Promise<shiki.Highlighter>>();

// Map of old theme names to new names to preserve compatibility when we upgrade shiki
const compatThemes: Record<string, string> = {
'material-darker': 'material-theme-darker',
'material-default': 'material-theme',
'material-lighter': 'material-theme-lighter',
'material-ocean': 'material-theme-ocean',
'material-palenight': 'material-theme-palenight',
};

const normalizeTheme = (theme: string | shiki.IShikiTheme) => {
if (typeof theme === 'string') {
return compatThemes[theme] || theme;
} else if (compatThemes[theme.name]) {
return { ...theme, name: compatThemes[theme.name] };
} else {
return theme;
}
};

const remarkShiki = async (
{ langs = [], theme = 'github-dark', wrap = false }: ShikiConfig,
scopedClassName?: string | null
) => {
theme = normalizeTheme(theme);
const cacheID: string = typeof theme === 'string' ? theme : theme.name;
let highlighterAsync = highlighterCacheAsync.get(cacheID);
if (!highlighterAsync) {
Expand Down

0 comments on commit e79e377

Please sign in to comment.